我正在努力为大学设置我的Qt,而且我遇到了一些问题.我正在运行Windows 8,我不确定哪个版本的Qt或QtCreator而不是最新版本 - 我们获得了版本安装程序所以我们必须使用这个版本,尽管我在QtCreator设置之前自己安装了最新的MinGW.
我在QtCreator中尝试了一些演示代码,当我尝试运行以下代码时,我收到错误"无法识别的命令行选项"-WI".
#include <QtCore/QCoreApplication>
#include <QtGui/QMessageBox>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QMessageBox msgBox;
msgBox.setText("This is some text.");
msgBox.exec();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
我需要完成我的任务,当我得到所有这些奇怪的错误时,我不确定如何做到这一点.任何帮助,将不胜感激.
提前致谢!
*编辑*
这是我在构建过程中可以在QtCreator中找到的错误输出.
Running build steps for project TestProject...
Configuration unchanged, skipping qmake step.
Starting: "C:/MinGW/bin/mingw32-make.exe" -w
mingw32-make: Entering directory 'C:/Users/Nick/Documents/Qt Projects/TestProject-build-desktop'
C:/MinGW/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/Nick/Documents/Qt Projects/TestProject-build-desktop'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug\TestProject.exe debug/main.o -L"c:\Qt\2010.04\qt\lib" -lQtCored4
Makefile.Debug:73: recipe for target 'debug\TestProject.exe' failed
mingw32-make[1]: Leaving directory 'C:/Users/Nick/Documents/Qt Projects/TestProject-build-desktop'
Makefile:34: recipe for target 'debug' failed
mingw32-make: Leaving directory 'C:/Users/Nick/Documents/Qt Projects/TestProject-build-desktop'
g++: error: unrecognized command line option '-Wl'
mingw32-make[1]: *** [debug\TestProject.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:/MinGW/bin/mingw32-make.exe" exited with code %2.
Error while building project TestProject (target: Desktop)
When executing build step 'Make'
Run Code Online (Sandbox Code Playgroud)
以下是QtCreator生成的.pro文件的内容:
QT += core
QT -= gui
TARGET = TestProject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
Run Code Online (Sandbox Code Playgroud)
正如 Mats 所说,问题在于-Wl命令行中的额外内容。
这是由于 QT conf 文件中的错误造成的,幸运的是,这可以“永久”(本地)修复。
您需要编辑这些文件之一(可能是两个)(通常位于C:\Qt\2010.02\qt\mkspecs):
mkspecs\default\qmake.confmkspecs\win32-g++\qmake.conf改变这个:
QMAKE_LFLAGS = -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
QMAKE_LFLAGS_EXCEPTIONS_ON = -mthreads -Wl
Run Code Online (Sandbox Code Playgroud)
对此:
QMAKE_LFLAGS = -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
QMAKE_LFLAGS_EXCEPTIONS_ON = -mthreads
Run Code Online (Sandbox Code Playgroud)
因为不知何故,-Wl,第一行的开头错误地位于第二行的末尾。
进行此编辑后,如果您清理并重建项目,您将不再看到该错误。
笔记: