qt creator 中有很多未定义的引用
lots of undefined reference in qt creator
我正在使用 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
仅这一行就有数百个这样的错误。
不知道是什么问题。
编辑:编译输出如下
C:\Qt\Qt5.7.0.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.7\msvc2015\lib C:\Qt\Qt5.7.0.7\msvc2015\lib\qtmaind.lib -LC:\utils\postgresql\pgsql\lib -LC:\utils\my_sql\my_sql\lib -lshell32 C:\Qt\Qt5.7.0.7\msvc2015\lib\Qt5Widgetsd.lib C:\Qt\Qt5.7.0.7\msvc2015\lib\Qt5Guid.lib C:\Qt\Qt5.7.0.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':
...
您的问题可能是您混用了 MinGW 和 MSVC。看这里:
C:\Qt\Qt5.7.0.7\msvc2015\bin\qmake.exe -spec win32-g++
这里:
C:\Qt\Qt5.7.0.7\msvc2015\lib\Qt5Widgetsd.lib
当然 MinGW g++ 不能 link 到 MSVC 库。它们具有不同的二进制格式和命名约定。最简单的处理方法是安装单一版本的 Qt。如果您想要 MinGW,请下载 MinGW 二进制文件。它们与 MinGW 版本捆绑在一起,并且可以独立运行。
我正在使用 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
仅这一行就有数百个这样的错误。
不知道是什么问题。 编辑:编译输出如下
C:\Qt\Qt5.7.0.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.7\msvc2015\lib C:\Qt\Qt5.7.0.7\msvc2015\lib\qtmaind.lib -LC:\utils\postgresql\pgsql\lib -LC:\utils\my_sql\my_sql\lib -lshell32 C:\Qt\Qt5.7.0.7\msvc2015\lib\Qt5Widgetsd.lib C:\Qt\Qt5.7.0.7\msvc2015\lib\Qt5Guid.lib C:\Qt\Qt5.7.0.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':
...
您的问题可能是您混用了 MinGW 和 MSVC。看这里:
C:\Qt\Qt5.7.0.7\msvc2015\bin\qmake.exe -spec win32-g++
这里:
C:\Qt\Qt5.7.0.7\msvc2015\lib\Qt5Widgetsd.lib
当然 MinGW g++ 不能 link 到 MSVC 库。它们具有不同的二进制格式和命名约定。最简单的处理方法是安装单一版本的 Qt。如果您想要 MinGW,请下载 MinGW 二进制文件。它们与 MinGW 版本捆绑在一起,并且可以独立运行。