10

I am trying to remind myself some C++, and also learn about Qt.

I am working on Windows. I have installed Qt (5.1.0), MinGW (g++ 4.6.2), Gnu Make (3.81).

I am trying to compile a simple Qt app. The most basic case is this:

#include <QtWidgets>
#include <QtGui>

int main (int argc, char* argv[]) {               
    QApplication app(argc, argv);                  
    QTextStream cout(stdout);                               
    return EXIT_SUCCESS;
}

The project file is:

TEMPLATE = app
TARGET = example1
INCLUDEPATH += .

# Input
SOURCES += fac1.cpp
QT += gui widgets core

When I run

qmake

it generates the Makefile.

But then with make I get this:

C:\src\early-examples\example1>make
make -f Makefile.Release
make[1]: Entering directory `C:/src/early-examples/example1'
g++ -Wl,-s -Wl,-subsystem,console -mthreads -o release\example1.exe release/fac1.o  -LC:\Qt\Qt5.1.0\\5.1.0\msvc2012_64\lib -lQt5Widgets -lQt5Gui -lQt5Core -llibEGL -llibGLESv2 -lgdi32 -luser32
release/fac1.o:fac1.cpp:(.text.startup+0x2e): undefined reference to `_imp___ZN12QApplicationC1ERiPPci'
release/fac1.o:fac1.cpp:(.text.startup+0x37): undefined reference to `_imp___ZN12QApplicationD1Ev'
collect2: ld returned 1 exit status
make[1]: *** [release\example1.exe] Error 1
make[1]: Leaving directory `C:/src/early-examples/example1'
make: *** [release] Error 2

Can you tell me what is wrong?

10
  • 2
    It looks like you are mixing compilers here. Why are you using visual studio libraries with gcc?
    – drescherjm
    Commented Aug 15, 2013 at 19:51
  • 1
    I am trying to use g++, but there might me some settings/env variables that I am not aware of. How can you tell?
    – ynka
    Commented Aug 15, 2013 at 19:53
  • 1
    Or are you saying I have to use Visual Studio to use Qt?
    – ynka
    Commented Aug 15, 2013 at 19:53
  • 1
    You have "-LC:\Qt\Qt5.1.0\\5.1.0\msvc2012_64\lib" in the output you posted.
    – drescherjm
    Commented Aug 15, 2013 at 19:54
  • 1
    Yes. You should have a mingw version.
    – drescherjm
    Commented Aug 15, 2013 at 19:55

2 Answers 2

11

The problem here is you appear to be using Visual Studio 2012 libraries for your mingw builds. You need to link to the mingw compiled Qt instead.

2
  • 1
    Yes. I downloaded (from qt-project.org/downloads) Qt 5.1.0 for Windows 64-bit (VS 2012, 525 MB) instead of Qt 5.1.0 for Windows 32-bit (MinGW 4.8, OpenGL, 666 MB). Works fine now!
    – ynka
    Commented Aug 15, 2013 at 21:04
  • 2
    This is the reason why there are so many Qt binary releases on the downloads. Even mixing different visual studio versions can give you problems.
    – drescherjm
    Commented Aug 15, 2013 at 21:06
1

Add "greaterThan(QT_MAJOR_VERSION, 4): QT += widgets" into your .pro file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.