Problem compile example in windows
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:
Code:
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___ZN6QLabelC1ERK7QStringP7QWidget6QFlagsIN2Qt10WindowTypeEE'
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
Re: Problem compile example in windows
It looks like you are not linking against Qt.
Can you show your pro file contents?
Re: Problem compile example in windows
THz for reply...
I haven't file .pro, I only main.cpp file.
main.cpp
Code:
#include <QApplication.h>
#include <QLabel.h>
int main(int argc, char *argv[])
{
label->show();
return app.exec();
}
:(
Re: Problem compile example in windows
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:
Code:
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.
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 ;)