Results 1 to 4 of 4

Thread: Problem compile example in windows

  1. #1
    Join Date
    Jul 2007
    Posts
    24
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem compile example in windows

    Hi, Im newbie in QT

    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.

    The error is:
    Qt Code:
    1. 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
    2. C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text+0x180): undefined reference to `__imp___ZN12QApplicationC1ERiPPci'
    3. C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text+0x214): undefined reference to `__imp___ZN6QLabelC1ERK7QStringP7QWidget6QFlagsIN2Qt10WindowTypeEE'
    4. C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text+0x2da): undefined reference to `__imp___ZN12QApplication4execEv'
    5. C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text+0x2f7): undefined reference to `QApplication::~QApplication()'
    6. C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text+0x326): undefined reference to `QApplication::~QApplication()'
    7. C:\DOCUME~1\WALTER~1.GAR\LOCALS~1\Temp/ccmoosdH.o:main.cpp:(.text$_ZN7QStringD1Ev[QString::~QString()]+0x20): undefined reference to `__imp___ZN7QString4freeEPNS_4DataE'
    8. 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
    9. _helperEPKci'
    10. collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

    Which can be the problem?

    Thz

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem compile example in windows

    It looks like you are not linking against Qt.
    Can you show your pro file contents?

  3. #3
    Join Date
    Jul 2007
    Posts
    24
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Problem compile example in windows

    THz for reply...

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

    main.cpp
    Qt Code:
    1. #include <QApplication.h>
    2. #include <QLabel.h>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. QLabel *label = new QLabel("Hello Qt!");
    8. label->show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 


  4. #4
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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:
    Qt Code:
    1. 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
    To copy to clipboard, switch view to plain text mode 

    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

Similar Threads

  1. Problem compile QT embedded 3.3.6
    By webquinty in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 27th June 2008, 08:55
  2. problem to compile exemple qt4 with xlC compiler
    By poulacou in forum Qt Programming
    Replies: 1
    Last Post: 16th April 2008, 14:59
  3. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 11:47
  4. Replies: 4
    Last Post: 12th January 2006, 04:16
  5. QProcess problem with windows batch file
    By bood in forum Qt Programming
    Replies: 11
    Last Post: 6th January 2006, 08:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.