5

I'm trying to set up my Qt for college and I'm running into some issues. I'm running Windows 8, and I'm not sure which version of Qt or QtCreator but not the latest - we were given the version installer so we must use this one, although I did install the latest MinGW myself before the QtCreator setup.

I tried some demo code in QtCreator and I got the error "Unrecognized Command Line Option "-WI" when I try run the following code.

#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();
}

I need to do my assignment and I'm not sure how I can do it when I'm getting all of these strange errors. Any help would be appreciated.

Thanks in advance!

* EDIT *

This is the error output that I can find in QtCreator during the build process.

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'

Here are the contents of the .pro file generated by QtCreator :

QT       += core

QT       -= gui

TARGET = TestProject
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app


SOURCES += main.cpp
Nick Corin
  • 2,214
  • 5
  • 25
  • 46
  • `-Wl` is an argument passed to the linker when using gcc "as the linker". Without seeing exactly what the linker command is, it's hard to say exactly what is going on. – Mats Petersson Mar 09 '14 at 13:58
  • How can I get that to you? – Nick Corin Mar 09 '14 at 14:00
  • Not sure, I don't work much with Qt. – Mats Petersson Mar 09 '14 at 14:05
  • I edited the question and added in the console output if that helps you at all? – Nick Corin Mar 09 '14 at 14:13
  • The Qt Creator version you can find out via the “About Qt Creator" dialog, the configured Qt versions via Preferences->Build & Run->Qt Versions. Besides, your code won’t work because QMessageBox requires a QApplication, not just a QCoreApplication. – Frank Osterfeld Mar 09 '14 at 14:16
  • It says that it's QtCreator 2.0 based on Qt 4.7.0 (32-bit). I can't find the Preferences pane though. Neither the Build & Run tab. – Nick Corin Mar 09 '14 at 14:19
  • Important file for this problem is the `.pro` file (*qmake* project file). Add that to question. – hyde Mar 09 '14 at 16:42
  • Also, seems quite old Qt Creator version... You could install a newer one and use that with your current Qt version, if you want, no problem and easy to configure. – hyde Mar 09 '14 at 16:46
  • Will a newer QtCreator not mess with anything else? I just installed everything like I was told in our introduction to the subject. I will add the edit now with the .pro file. – Nick Corin Mar 09 '14 at 17:08
  • As long as you install the new QtC (note: you want the standalone one, not full SDK) in separate folder, it should be completely separate application, and not touch the old QtC you have now. Only thing it messes with is `.pro.user` file under project, which contains Qt Creator's own settings for project, and is generated when you open a new project for the first time (take backup of current one if you want to play it safe). – hyde Mar 09 '14 at 17:17
  • Try removing `QT-=gui`, then rerun qmake (from Build menu) and rebuild project. If it works then, it may be a bug in Qt4.7, perhaps Win8 incompatibility. – hyde Mar 09 '14 at 17:22
  • Nothing changes. Still get exactly the same error if I rerun the code with taking out the QT -= gui – Nick Corin Mar 09 '14 at 17:33
  • Well, something adds extra `-Wl`, but tricky to know what. Could be Win8-specific incompatibility, could be botched Qt installation, could be genuine bug in that Qt version for that platform... :-/ – hyde Mar 09 '14 at 18:31

2 Answers2

4

The problem is clearly:

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

I'm not sure exaclty how this is compiled, but to me it looks like a makefile with -Wl${somestuff} and for some reason ${somestuff} is not defined. Either that, or there is a spurious -Wl in the commendline for the link command, but that seems less likely.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • Well, this is what I found not in the Makefile but in the Makefile.Debug. LFLAGS = -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl – Nick Corin Mar 09 '14 at 14:36
  • Right, so remove the extra `-Wl` on the end (but I expect the makefile is generated, so the generator probably has some "empty variable" that it prepends with `-Wl`. – Mats Petersson Mar 09 '14 at 14:38
  • Yeah, the Makefile is generated. And I'm not sure how to sort it out permanently. – Nick Corin Mar 09 '14 at 14:43
4

As Mats says the problem is the extra -Wl in the command line.

This is due to a bug in the QT conf files, and thankfully this can be fixed "permanently" (locally).

You need to edit one (possibly both) of these files (often in C:\Qt\2010.02\qt\mkspecs):

  • mkspecs\default\qmake.conf
  • mkspecs\win32-g++\qmake.conf

changing this:

QMAKE_LFLAGS        = -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
QMAKE_LFLAGS_EXCEPTIONS_ON = -mthreads -Wl

to this:

QMAKE_LFLAGS        = -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
QMAKE_LFLAGS_EXCEPTIONS_ON = -mthreads

because somehow the -Wl, from the start of the first line is wrongly on the end of the second line.

After this edit, if you clean and then rebuild your project you will no longer see the error.

Notes:

  • this same bug causes this issue too, so thanks to leemes for his answer there)
  • it is fixed in Qt since version 4.7 I believe
Community
  • 1
  • 1
sparrowt
  • 2,641
  • 25
  • 24