PDA

View Full Version : Problem compile example in windows



walito
10th December 2008, 11:58
Hi, Im newbie in QT :D

I installed codeblocks with MinGW and now installed QT, in the install I selected MinGW from codeblock directory, but I need compile from command line.

I try compile the example "hello world", but I have many error. :confused:

The error is:


E:\Qt\test1>g++ -I"C:\Qt\4.4.3\include\Qt" -I"C:\Qt\4.4.3\include" -L"C:\Qt\4.4.3\lib" main.cpp -o main.exe
C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text+0x180): undefined reference to `__imp___ZN12QApplicationC1ERiPPci'
C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text+0x214): undefined reference to `__imp___ZN6QLabelC1ERK7QStringP7QWidget6QFlagsIN2 Qt10WindowTypeEE'
C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text+0x2da): undefined reference to `__imp___ZN12QApplication4execEv'
C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text+0x2f7): undefined reference to `QApplication::~QApplication()'
C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text+0x326): undefined reference to `QApplication::~QApplication()'
C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text$_ZN7QStringD1Ev[QString::~QString()]+0x20): undefined reference to `__imp___ZN7QString4freeEPNS_4DataE'
C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text$_ZN7QStringC1EPKc[QString::QString(char const*)]+0x19): undefined reference to `__imp___ZN7QString16fromAscii
_helperEPKci'
collect2: ld returned 1 exit status


Which can be the problem? :confused:

Thz

high_flyer
10th December 2008, 12:08
It looks like you are not linking against Qt.
Can you show your pro file contents?

walito
10th December 2008, 13:24
THz for reply...

I haven't file .pro, I only main.cpp file.

main.cpp


#include <QApplication.h>
#include <QLabel.h>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}


:(

rexi
10th December 2008, 21:41
As far as I know CodeBlocks generates Makefiles itself and doesn't directly support Qt, is that why you are compiling from the command line?

Anyway, the command to compile should look like this:

E:\Qt\test1>g++ -I"C:\Qt\4.4.3\include\Qt" -I"C:\Qt\4.4.3\include" -L"C:\Qt\4.4.3\lib" -lQtGui -lQtCore main.cpp -o main.exe

Note the addition of -lQtCore and -lQtGui. If you used .pro files and qmake, it would automatically generate Makefiles so you don't have to run the compiler yourself. To learn more about qmake and the .pro syntax you can check out the qmake manual (http://doc.trolltech.com/4.4/qmake-manual.html).

You should probably have a look at QDevelop, or Qt Software's Eclipse Integration or probably even the still-unfinished Qt Creator if you want to write applications using Qt. They make life a whole lot easier ;)