Results 1 to 6 of 6

Thread: undefined reference Error in helloworld program !

  1. #1
    Join Date
    Jun 2009
    Location
    Bangalore
    Posts
    21
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question undefined reference Error in helloworld program !

    Hi,

    I am again new to Qt world !

    I have created a Helloworld Program in Qt 4.7.0 ( 32 bit windows ), using QtCreater 2.0.1.

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QtGui/QLabel>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7.  
    8. QLabel label("Hello World!");
    9. label.show();
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    when I build this code getting the following errors,

    Qt Code:
    1. main.cpp:11: undefined reference to `_imp___ZN6QLabelD1Ev'
    2.  
    3. collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

    could anybody let me know, what I am doing wrong in this simple code ???

    Thanks,
    Pradeep.

  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: undefined reference Error in helloworld program !

    change QCoreApplication to QApplication. - and the corresponding include as well.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jun 2009
    Location
    Bangalore
    Posts
    21
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: undefined reference Error in helloworld program !

    Hi,

    Thanks for quick reply, but the solution is not working for me !
    now the code is changed to

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

    but i am getting the following errors:

    main.cpp:1:24: error: QApplication: No such file or directory

    main.cpp:6: error: variable 'QApplication a' has initializer but incomplete type

    when I choolse "Qt Console Application", while creating new project, by default QtCreator includes QtCoreApplicaion. so is that wrong ?

    -Pradeep-

  4. #4
    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: undefined reference Error in helloworld program !

    #include <QtGui\QApplication>

    when I choolse "Qt Console Application", while creating new project, by default QtCreator includes QtCoreApplicaion. so is that wrong ?
    No, QtCreator is doing it right.
    But a console application by definition has no GUI. (I am not talking about ncourses style GUI).
    Yet you are initializing gui elements in your code!
    So either use GUI and make a GUI application, or a console one, without GUI.
    But trying to use GUI elements in non GUI application wont work.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. The following user says thank you to high_flyer for this useful post:

    prady (16th December 2010)

  6. #5
    Join Date
    Jun 2009
    Location
    Bangalore
    Posts
    21
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: undefined reference Error in helloworld program !

    Yes I understand now, thank you.

    but only adding #include <QtGui\QApplication> is not fixing my problem.
    I have modified "QT -= gui" line in .pro file to "QT += gui" helps to solve those errors.

    I assume this tells compiler to include gui libraries.

    Thanks again,
    Pradeep.

  7. #6
    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: undefined reference Error in helloworld program !

    yes, that is correct.
    In my first answer I was not aware you configured a console application.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Plugin compiler error: undefined reference
    By FinderCheng in forum Qt Programming
    Replies: 8
    Last Post: 1st May 2010, 17:49
  2. Getting Undefined Reference Error
    By A.H.M. Mahfuzur Rahman in forum Qt Programming
    Replies: 2
    Last Post: 22nd June 2009, 03:12
  3. Error - undefined reference qMain
    By tpf80 in forum Newbie
    Replies: 4
    Last Post: 23rd February 2009, 08:54
  4. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 15:28
  5. Undefined Reference error!!!
    By Kapil in forum Newbie
    Replies: 25
    Last Post: 28th March 2006, 13:03

Tags for this Thread

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.