簡體   English   中英

qt creator中有很多未定義的引用

[英]lots of undefined reference in qt creator

我使用的是Win7 32bit,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':
...

您的問題可能是您正在混合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版本,並且以獨立的方式工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM