完整报错如下:
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文件夹。重新运行,项目正常编译!

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

6442

被折叠的 条评论
为什么被折叠?



