Clion开发Qt报错:collect2.exe: error: ld returned 1 exit statusmingw32-make.exe[3]: *** [CMakeFiles\unti

该报错是由于新建Qt项目时CMake配置路径不正确导致的,具体表现为多个Qt库函数的undefinedreference。解决方法是在QtCMake设置中选择MinGW的lib目录下的cmake文件夹,确保链接器能正确找到库文件,从而成功编译项目。
摘要由CSDN通过智能技术生成

完整报错如下:

CMakeFiles\untitled.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Guangsheng Li/Desktop/untitled/main.cpp:5: undefined reference to `__imp__ZN12QApplicationC1ERiPPci'
C:/Users/Guangsheng Li/Desktop/untitled/main.cpp:6: undefined reference to `__imp__ZN11QPushButtonC1ERK7QStringP7QWidget'
C:/Users/Guangsheng Li/Desktop/untitled/main.cpp:8: undefined reference to `__imp__ZN7QWidget4showEv'
C:/Users/Guangsheng Li/Desktop/untitled/main.cpp:9: undefined reference to `__imp__ZN12QApplication4execEv'
C:/Users/Guangsheng Li/Desktop/untitled/main.cpp:6: undefined reference to `__imp__ZN11QPushButtonD1Ev'
C:/Users/Guangsheng Li/Desktop/untitled/main.cpp:5: undefined reference to `__imp__ZN12QApplicationD1Ev'
C:/Users/Guangsheng Li/Desktop/untitled/main.cpp:6: undefined reference to `__imp__ZN11QPushButtonD1Ev'
C:/Users/Guangsheng Li/Desktop/untitled/main.cpp:5: undefined reference to `__imp__ZN12QApplicationD1Ev'
CMakeFiles\untitled.dir/objects.a(main.cpp.obj): In function `QString::QString(char const*)':
C:/ProgramData/Anaconda3/Library/include/qt/QtCore/qstring.h:659: undefined reference to `__imp__ZN7QString16fromAscii_helperEPKci'
CMakeFiles\untitled.dir/objects.a(main.cpp.obj): In function `QWidget::resize(int, int)':
C:/ProgramData/Anaconda3/Library/include/qt/QtWidgets/qwidget.h:838: undefined reference to `__imp__ZN7QWidget6resizeERK5QSize'
CMakeFiles\untitled.dir/objects.a(main.cpp.obj): In function `QTypedArrayData<unsigned short>::deallocate(QArrayData*)':
C:/ProgramData/Anaconda3/Library/include/qt/QtCore/qarraydata.h:237: undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\untitled.dir\build.make:125: untitled.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:96: CMakeFiles/untitled.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:103: CMakeFiles/untitled.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:137: untitled] Error 2

报错原因:新建Qt项目时没有选择MinGW下的CMake路径

 解决办法:创建项目时在Qt CMake前缀路径选择MinGW文件夹下lib目录里的cmake文件夹。重新运行,项目正常编译! 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值