如果简单的演示应用(控制台项目模板(使用 qmake 命令行编译,请先尝试:
SET PATH=%PATH%;C:QtQt5.9.15.9.1mingw53_32bin;C:QtQt5.9.1Toolsmingw530_32bin
C:QtQt5.9.15.9.1mingw53_32binqmake.exe -makefile C:Softwaretest.pro -spec win32-g++
mingw32-make.exe
pause
现在尝试重新链接应用程序:
C:QtQt5.9.1Toolsmingw530_32binld -o test releasemain.o -LC:QtQt5.9.15.9.1mingw53_32bin -lQt5Core --verbose > ld_dump.txt
pause
错误
main.o undefined reference to _Unwind_Resume
main.o undefined reference to __gxx_personality_v0
相比之下,一个稍微复杂的应用程序与QtWidgets生产更多的错误(当然,我在链接器蝙蝠文件中添加了缺少的Qt库(
moc_widget.o undefined reference to strcmp
moc_widget.o QObject undefined reference to vtable for __xyyabiv1:: __class_type_info
...
谷歌搜索错误 1+2 他们说这可能是由不同的编译器引起的。但我使用相同的工具。
专业文件看起来像
QT += core
QT -= gui
CONFIG += c++11
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
我是否需要将某种 c++11 标志传递给链接器ld
?
我认为ld需要更多的信息(例如,它对stdc++一无所知(。为什么不使用 g++ 进行链接呢?像这样的行应该有效:
C:QtQt5.9.1Toolsmingw530_32bing++.exe
-Wl,-rpath,C:QtQt5.9.15.9.1mingw53_32bin
-o test releasemain.o -LC:QtQt5.9.15.9.1mingw53_32bin -lQt5Core