2016-08-21 2 views
1

Я использую Win7 32bit, MinGW и Qt 5.7.0. Я начинаю с этим и хочу изучить некоторые вещи в GUI. Я получаю сотни неопределенной ссылки ошибки при выполнении его. это мой файл .pro.много неопределенных ссылок в создателе qt

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 

Есть 100s таких ошибок с помощью всего это одна линия.

Я не знаю, в чем проблема. Edit: Компиляция выход ниже

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': 
... 
+1

пожалуйста, напишите ваш сценарий сборки слишком –

+0

Посмотрите здесь http://stackoverflow.com/questions/18260607/c-qt-undefined-reference-to-imp-zn12qapplicationc1erippci – 5208760

+0

сделать это из меню сборки может работать: чистые все run qmake построить все – mostafaTmj

ответ

3

Ваша проблема, вероятно, что вы смешиваете MinGW и MSVC. Смотрите здесь:

C: \ Qt \ Qt5.7.0 \ 5,7 \ msvc2015 \ Bin \ qmake.exe -spec win32-г ++

И здесь:

C: \ Qt \ Qt5.7.0 \ 5,7 \ msvc2015 \ Lib \ Qt5Widgetsd.lib

Конечно, MinGW g ++ не может ссылаться на библиотеки MSVC. Они имеют разные бинарные форматы и соглашения об именах. Самый простой способ справиться с этим - установить одну версию Qt. Если вы хотите MinGW, тогда загрузите двоичные файлы MinGW. Они поставляются в комплекте с версией MinGW и отлично работают в автономном режиме.

Смежные вопросы