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

时间:2021-11-29 04:53:48

I am trying to compile a Qt hello world program. I am using Qt 5.2.0 on Windows 64 bit. This is my code

我正在尝试编译一个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();
 }

When i run the application i get the following run time errors:

当我运行应用程序时,我得到以下运行时错误:

 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 file

.pro文件

   QT       += core

   QT       -= gui
   TARGET = QtTest
   CONFIG   += console
   CONFIG   -= app_bundle

   TEMPLATE = app


   SOURCES += main.cpp

I want to use Qt with MinGW .I am currently using Qt creatore for 64 bit Visual Studio 2012 compiler. Since 64 bit MinGW is not available in the downloads for 5.2.0

我想用Qt和MinGW,我现在使用Qt creatore 64位Visual Studio 2012编译器。因为在5.2.0版的下载中没有64位MinGW。

Can someone help me solve these reference errors?

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

1 个解决方案

#1


1  

Why would you download a VS2012 version of Qt if you don't have, well, VS2012?

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

Download a version that matches the exact compiler you have. If there is none, download the sources and compile it yourself.

下载一个与你的编译器匹配的版本。如果没有,请下载源代码并自己编译。

If you want to avoid the complications of self-compilation, then VS2012 Express is perfectly adequate to develop with Qt. It's the same compiler as the paid-for versions, and if you develop using Qt Creator, then you really don't care for whatever limitations the express edition IDE might have. It works great.

如果您想避免自编译的复杂性,那么VS2012 Express完全可以与Qt一起开发,它与付费版本是相同的编译器,如果您使用Qt创建者,那么您真的不关心Express edition IDE可能有什么限制。它的工作原理。

Another possibility is to use the mingw build of Qt. During setup, you can enable the installation of the MinGW 4.8.0 toolchain. This gives you a complete development environment, with the IDE, the Qt headers and binaries, and a toolchain.

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

#1


1  

Why would you download a VS2012 version of Qt if you don't have, well, VS2012?

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

Download a version that matches the exact compiler you have. If there is none, download the sources and compile it yourself.

下载一个与你的编译器匹配的版本。如果没有,请下载源代码并自己编译。

If you want to avoid the complications of self-compilation, then VS2012 Express is perfectly adequate to develop with Qt. It's the same compiler as the paid-for versions, and if you develop using Qt Creator, then you really don't care for whatever limitations the express edition IDE might have. It works great.

如果您想避免自编译的复杂性,那么VS2012 Express完全可以与Qt一起开发,它与付费版本是相同的编译器,如果您使用Qt创建者,那么您真的不关心Express edition IDE可能有什么限制。它的工作原理。

Another possibility is to use the mingw build of Qt. During setup, you can enable the installation of the MinGW 4.8.0 toolchain. This gives you a complete development environment, with the IDE, the Qt headers and binaries, and a toolchain.

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