编译Qt hello world程序时未定义的引用错误

时间:2014-02-03 11:15:27

标签: c++ qt

我正在尝试编译一个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编译器。由于在5.2.0的下载中没有64位MinGW

有人可以帮我解决这些参考错误吗?

1 个答案:

答案 0 :(得分:1)

如果你没有,那么为什么要下载VS2012版本的Qt?VS2012?

下载与您拥有的确切编译器相匹配的版本。如果没有,请下载源代码并自行编译。

如果你想避免自编译的复杂性,那么VS2012 Express完全足以用Qt开发。它与付费版本的编译器相同,如果您使用Qt Creator开发,那么您实际上并不关心快速版IDE可能具有的任何限制。它很棒。

另一种可能性是使用Qt的mingw构建。在安装过程中,您可以启用MinGW 4.8.0工具链的安装。这为您提供了一个完整的开发环境,包括IDE,Qt标头和二进制文件以及工具链。

相关问题