我正在使用Win7 32位,MinGW和Qt 5.7.0。我是初学者,想学习一些GUI的东西。我在执行它时遇到了数百个未定义的引用错误。 这是我的.pro文件。
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = new
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
我只在函数中编写了一行代码:
void MainWindow::on_pushButton_clicked()
{
ui->label->setText("lkj");
}
我收到如下所示的完整错误:
C:\Users\xxxxx\Documents\new\main.cpp:6: error: undefined reference to _imp___ZN12QApplicationC1ERiPPci
C:\Users\xxxxx\Documents\new\main.cpp:8: error: undefined reference to _imp___ZN7QWidget4showEv
C:\Users\xxxxx\Documents\new\main.cpp:10: error: undefined reference to _imp___ZN12QApplication4execEv
只有这一行有100多个这样的错误。
我不知道问题是什么。 编辑:编译输出低于
C:\Qt\Qt5.7.0\5.7\msvc2015\bin\qmake.exe -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug" -o Makefile ..\new\new.pro
C:/Program Files/mingw-w64/i686-6.1.0-posix-dwarf-rt_v5-rev1/mingw32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/Anant/Documents/build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug'
g++ -Wl,-subsystem,windows -mthreads -o debug\new.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -lmingw32 -LC:\Qt\Qt5.7.0\5.7\msvc2015\lib C:\Qt\Qt5.7.0\5.7\msvc2015\lib\qtmaind.lib -LC:\utils\postgresql\pgsql\lib -LC:\utils\my_sql\my_sql\lib -lshell32 C:\Qt\Qt5.7.0\5.7\msvc2015\lib\Qt5Widgetsd.lib C:\Qt\Qt5.7.0\5.7\msvc2015\lib\Qt5Guid.lib C:\Qt\Qt5.7.0\5.7\msvc2015\lib\Qt5Cored.lib
Warning: corrupt .drectve at end of def file
debug/main.o: In function `Z5qMainiPPc':
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/../new/main.cpp:6: undefined reference to `_imp___ZN12QApplicationC1ERiPPci'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/../new/main.cpp:8: undefined reference to `_imp___ZN7QWidget4showEv'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/../new/main.cpp:10: undefined reference to `_imp___ZN12QApplication4execEv'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/../new/main.cpp:6: undefined reference to `_imp___ZN12QApplicationD1Ev'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/../new/main.cpp:6: undefined reference to `_imp___ZN12QApplicationD1Ev'
debug/mainwindow.o: In function `ZN10MainWindowC2EP7QWidget':
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/../new/mainwindow.cpp:6: undefined reference to `_imp___ZN11QMainWindowC2EP7QWidget6QFlagsIN2Qt10WindowTypeEE'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/../new/mainwindow.cpp:6: undefined reference to `_imp___ZN11QMainWindowD2Ev'
debug/mainwindow.o: In function `ZN10MainWindowD2Ev':
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/../new/mainwindow.cpp:11: undefined reference to `_imp___ZN11QMainWindowD2Ev'
debug/mainwindow.o: In function `ZN10MainWindow21on_pushButton_clickedEv':
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/../new/mainwindow.cpp:18: undefined reference to `_imp___ZN6QLabel7setTextERK7QString'
debug/mainwindow.o: In function `ZN7QStringC1EPKc':
C:/Qt/Qt5.7.0/5.7/msvc2015/include/QtCore/qstring.h:664: undefined reference to `_imp___ZN7QString16fromAscii_helperEPKci'
debug/mainwindow.o: In function `ZN7QWidget6resizeEii':
C:/Qt/Qt5.7.0/5.7/msvc2015/include/QtWidgets/qwidget.h:835: undefined reference to `_imp___ZN7QWidget6resizeERK5QSize'
debug/mainwindow.o: In function `ZN13Ui_MainWindow7setupUiEP11QMainWindow':
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:39: undefined reference to `_imp___ZNK7QObject10objectNameEv'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:40: undefined reference to `_imp___ZN7QObject13setObjectNameERK7QString'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:42: undefined reference to `_imp___ZN7QWidgetC1EPS_6QFlagsIN2Qt10WindowTypeEE'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:43: undefined reference to `_imp___ZN7QObject13setObjectNameERK7QString'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:44: undefined reference to `_imp___ZN11QPushButtonC1EP7QWidget'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:45: undefined reference to `_imp___ZN7QObject13setObjectNameERK7QString'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:46: undefined reference to `_imp___ZN7QWidget11setGeometryERK5QRect'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:47: undefined reference to `_imp___ZN6QLabelC1EP7QWidget6QFlagsIN2Qt10WindowTypeEE'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:48: undefined reference to `_imp___ZN7QObject13setObjectNameERK7QString'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:49: undefined reference to `_imp___ZN7QWidget11setGeometryERK5QRect'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:50: undefined reference to `_imp___ZN11QMainWindow16setCentralWidgetEP7QWidget'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:51: undefined reference to `_imp___ZN8QMenuBarC1EP7QWidget'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:52: undefined reference to `_imp___ZN7QObject13setObjectNameERK7QString'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:53: undefined reference to `_imp___ZN7QWidget11setGeometryERK5QRect'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:54: undefined reference to `_imp___ZN11QMainWindow10setMenuBarEP8QMenuBar'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:55: undefined reference to `_imp___ZN8QToolBarC1EP7QWidget'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:56: undefined reference to `_imp___ZN7QObject13setObjectNameERK7QString'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:57: undefined reference to `_imp___ZN11QMainWindow10addToolBarEN2Qt11ToolBarAreaEP8QToolBar'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:58: undefined reference to `_imp___ZN10QStatusBarC1EP7QWidget'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:59: undefined reference to `_imp___ZN7QObject13setObjectNameERK7QString'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:60: undefined reference to `_imp___ZN11QMainWindow12setStatusBarEP10QStatusBar'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:64: undefined reference to `_imp___ZN11QMetaObject18connectSlotsByNameEP7QObject'
debug/mainwindow.o: In function `ZN13Ui_MainWindow13retranslateUiEP11QMainWindow':
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:69: undefined reference to `_imp___ZN16QCoreApplication9translateEPKcS1_S1_i'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:69: undefined reference to `_imp___ZN7QWidget14setWindowTitleERK7QString'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:70: undefined reference to `_imp___ZN16QCoreApplication9translateEPKcS1_S1_i'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:70: undefined reference to `_imp___ZN15QAbstractButton7setTextERK7QString'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:71: undefined reference to `_imp___ZN16QCoreApplication9translateEPKcS1_S1_i'
C:\Users\Anant\Documents\build-new-Clone_of_Desktop_Qt_5_7_0_MSVC2015_32bit-Debug/./ui_mainwindow.h:71: undefined reference to `_imp___ZN6QLabel7setTextERK7QString'
debug/mainwindow.o: In function `ZN15QTypedArrayDataItE10deallocateEP10QArrayData':
C:/Qt/Qt5.7.0/5.7/msvc2015/include/QtCore/qarraydata.h:228: undefined reference to `_imp___ZN10QArrayData10deallocateEPS_jj'
debug/mainwindow.o: In function `ZNK17QStaticStringDataILi10EE8data_ptrEv':
C:/Qt/Qt5.7.0/5.7/msvc2015/include/QtCore/qstring.h:207: undefined reference to `_imp___Z9qt_assertPKcS0_i'
debug/mainwindow.o: In function `ZNK17QStaticStringDataILi13EE8data_ptrEv':
...
答案 0 :(得分:3)
您的问题可能是您正在混合MinGW和MSVC。见这里:
C:\ Qt \ Qt5.7.0 \ 5.7 \ msvc2015 \ bin \ qmake.exe -spec win32-g ++
在这里:
C:\ Qt的\ Qt5.7.0 \ 5.7 \的 msvc2015 强> \ lib中\ Qt5Widgetsd.lib
当然MinGW g ++无法链接到MSVC库。它们具有不同的二进制格式和命名约定。处理它的最简单方法是安装单个版本的Qt。如果你想要MinGW,那么下载MinGW二进制文件。它们捆绑了MinGW版本,并且以独立的方式工作。