我正在尝试编译一个 Qt hello world 程序。我在 Windows 64 位上使用 Qt 5.2.0。 这是我的代码
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "Hello world";
return a.exec();
}
当我运行应用程序时,出现以下运行时错误:
mingw32-make[1]: Entering directory 'C:/Users/test/qt_creator_projects/build-QtTest- TestLocal_PC-Debug'
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_CORE_LIB -I..\QtTest -
I"D:\Qt\5.2.0\msvc2012_64\include" -I"D:\Qt\5.2.0\msvc2012_64\include\QtCore" -I"debug" -
I"." -I"D:\Qt\5.2.0\msvc2012_64\mkspecs\win32-g++" -o debug\main.o ..\QtTest\main.cpp
g++ -Wl,-subsystem,console -mthreads -o debug\QtTest.exe debug/main.o -
LD:\Qt\5.2.0\msvc2012_64\lib -lQt5Cored
debug/main.o: In function `main':
C:\Users\test\qt_creator_projects\build-QtTest-TestLocal_PC-
Debug/../QtTest/main.cpp:5: undefined reference to `_imp___ZN16QCoreApplicationC1ERiPPci'
C:\Users\test\qt_creator_projects\build-QtTest-TestLocal_PC- Debug/../QtTest/main.cpp:7: undefined reference to `_imp___ZN16QCoreApplication4execEv'
Makefile.Debug:77: recipe for target 'debug\QtTest.exe' failed
C:\Users\test\qt_creator_projects\build-QtTest-TestLocal_PC-
Debug/../QtTest/main.cpp:7: undefined reference to `_imp___ZN16QCoreApplicationD1Ev'
mingw32-make[1]: Leaving directory 'C:/Users/test/qt_creator_projects/build-QtTest- TestLocal_PC-Debug'
Makefile:34: recipe for target 'debug' failed
C:\Users\test\qt_creator_projects\build-QtTest-TestLocal_PC-Debug/../QtTest/main.cpp:7: undefined reference to `_imp___ZN16QCoreApplicationD1Ev'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [debug\QtTest.exe] Error 1
mingw32-make: *** [debug] Error 2
16:37:34: The process "D:\pen drive data\MinGW\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project QtTest (kit: TestLocal PC)
When executing step 'Make'
.pro文件
QT += core
QT -= gui
TARGET = QtTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
我想将 Qt 与 MinGW 一起使用。我目前正在将 Qt creatore 用于 64 位 Visual Studio 2012 编译器。由于 64 位 MinGW 在 5.2.0 的下载中不可用
谁能帮我解决这些引用错误?
最佳答案
如果您没有 VS2012,为什么要下载 VS2012 版本的 Qt?
下载与您拥有的编译器完全匹配的版本。如果没有,请下载源代码并自行编译。
如果你想避免自编译带来的麻烦,那么用Qt开发VS2012 Express完全够用了。它是与付费版本相同的编译器,如果您使用 Qt Creator 进行开发,那么您真的不关心 Express Edition IDE 可能有的任何限制。效果很好。
另一种可能性是使用 Qt 的 mingw 构建。在安装过程中,您可以启用 MinGW 4.8.0 工具链的安装。这为您提供了一个完整的开发环境,包括 IDE、Qt 头文件和二进制文件以及工具链。
关于c++ - 编译Qt hello world程序时出现Undefined reference错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21525905/