我试图建立与MinGW的编译器一个简单的Qt程序。我想最终端口我的Linux到Windows开发QT / C ++程序。我下载QT_4.3.5(这是什么我的程序使用),并从他们的网站的MinGW。我相信这是一个32位编译器。我使用“CMD”,以建立类似于我如何建立它在Linux中程序。我的程序如下图所示。
#include <QApplication>
#include <QPushButton>
#include <cstdio>
int main(int argc, char *argv[]) //This should work with QT4?
{
printf("Hello\n");
QApplication app(argc,argv);
QPushButton hello ("Hello world!");
hello.resize(100,30);
hello.show();
return app.exec();
}
我能够在Linux 5.7成功构建并运行此程序。所以,在窗口我创建了一个“main.cpp的”文件和使用qmake的同时创建.pro文件和Makefile文件。我使用从QT4.3.5 QMAKE。我用 “的qmake -project” 和QMAKE。它成功地建立双方的.pro文件和Makefile文件窗口。但是,当我运行make它给了我一个“无法识别的命令行选项‘-Wl’”
我相信有可能是与qmake的版本和MinGW的兼容性问题。在Makefile相关线上,
LFLAGS = -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows
然后我试图删除轮候册,它给错误说无法找到“使用--enable-自动导入”,“-enable-运行伪RELOC”,“-s”,“-subsystem,WINDOS”没有这样的文件或目录。
1)我应该如何调试这个问题?
2)我应该尝试minGW64版本?
------------------------------------编辑------------- ------------------------
我决定让QT的新版本进行测试。所以,我已经安装QT 5.6.3,我还使用附带QT5.6.3 minGW4.9。我也创建了QT项目文件(.pro),来喽。
TEMPLATE = app
TARGET = QT_Simple
INCLUDEPATH += .
# Input
SOURCES += main.cpp
LIBS += -L"C:\Qt\Qt5.6.3\5.6.3\mingw49_32\lib" \
-L"C:\Qt\Qt5.6.3\5.6.3\mingw49_32\lib" \
-lmingw32 \
-lqtmain \
-lQt5Core \
-lQt5Gui \
然后我运行“qmake的”创建Makefile文件。这里的相关章节。它看起来从以前的qmake有点不同
####### Compiler, tools and options
CC = gcc
CXX = g++
DEFINES = -DUNICODE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -
DQT_NEEDS_QMAIN
CFLAGS = -pipe -fno-keep-inline-dllexport -O2 -Wall -Wextra
$(DEFINES)
CXXFLAGS = -pipe -fno-keep-inline-dllexport -O2 -std=gnu++0x -frtti -
Wall -Wextra -fexceptions -mthreads $(DEFINES)
INCPATH = -I. -I. -IC:/Qt/Qt5.6.3/5.6.3/mingw49_32/include -
IC:/Qt/Qt5.6.3/5.6.3/mingw49_32/include/QtGui -
IC:/Qt/Qt5.6.3/5.6.3/mingw49_32/include/QtANGLE -
IC:/Qt/Qt5.6.3/5.6.3/mingw49_32/include/QtCore -Irelease -
IC:/Qt/Qt5.6.3/5.6.3/mingw49_32/mkspecs/win32-g++
LINKER = g++
LFLAGS = -Wl,-s -Wl,-subsystem,windows -mthreads
LIBS = -LC:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib -
LC:/utils/my_sql/my_sql/lib -LC:/utils/postgresql/pgsql/lib -
LC:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib -lmingw32
C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libqtmain.a -lshell32
C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Core.a
C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Gui.a
C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Core.a
QMAKE = C:/Qt/Qt5.6.3/5.6.3/mingw49_32/bin/qmake.exe
IDC = idc
IDL = midl
...........
我知道库文件是在上面的目录(例如:libQt5Core.a,libQt5Gui.a等)。但它给了我一个udefined引用错误。我相信,链接器无法找到文件。
C:\Users\Administrator\Documents\QT_Test\QT_Simple>mingw32-make
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'C:/Users/Administrator/Documents/QT_Test/QT_Simple'
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release/QT_Simple.exe release/main.o -LC:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib
-LC:/utils/my_sql/my_sql/lib -LC:/utils/postgresql/pgsql/lib -LC:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib -lmingw32
C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libqtmain.a -lshell32 C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Core.a
C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Gui.a C:/Qt/Qt5.6.3/5.6.3/mingw49_32/lib/libQt5Core.a
release/main.o:main.cpp:(.text+0x4d): undefined reference to `_imp___ZN12QApplicationC1ERiPPci'
release/main.o:main.cpp:(.text+0x7f): undefined reference to `_imp___ZN11QPushButtonC1ERK7QStringP7QWidget'
release/main.o:main.cpp:(.text+0xb0): undefined reference to `_imp___ZN7QWidget6resizeERK5QSize'
release/main.o:main.cpp:(.text+0xbc): undefined reference to `_imp___ZN7QWidget4showEv'
release/main.o:main.cpp:(.text+0xc2): undefined reference to `_imp___ZN12QApplication4execEv'
release/main.o:main.cpp:(.text+0xcd): undefined reference to `_imp___ZN11QPushButtonD1Ev'
release/main.o:main.cpp:(.text+0xd6): undefined reference to `_imp___ZN12QApplicationD1Ev'
release/main.o:main.cpp:(.text+0x120): undefined reference to `_imp___ZN12QApplicationD1Ev'
release/main.o:main.cpp:(.text+0x155): undefined reference to `_imp___ZN11QPushButtonD1Ev'
C:/Qt/Qt5.6.3/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: release/main.o:
bad reloc address 0x20 in section `.eh_frame'
C:/Qt/Qt5.6.3/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../.
./i686-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Makefile.Release:61: recipe for target 'release/QT_Simple.exe' failed
mingw32-make[1]: *** [release/QT_Simple.exe] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/Administrator/Documents/QT_Test/QT_Simple'
makefile:34: recipe for target 'release' failed
mingw32-make: *** [release] Error 2
我不知道为什么它找不到引用。是否有与不使用DLL文件(libQt5Core.dll等)做。我是否正确连接?
这个问题是我的QT工程文件(.PRO)。添加以下行,它的编译和运行成功。
QT += core gui widgets
最后QT_simple.pro文件看起来像以下,
QT += core gui widgets
TEMPLATE = app
TARGET = QT_Simple
INCLUDEPATH += .
# Input
SOURCES += main.cpp
LIBS += -L"C:\Qt\Qt5.6.3\5.6.3\mingw49_32\lib" \
-L"C:\Qt\Qt5.6.3\5.6.3\mingw49_32\lib" \
-lmingw32 \
-lqtmain \
-lQt5Core \
-lQt5Gui \
谢谢您的帮助!