LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-26-2010, 01:01 PM   #1
rohedin
LQ Newbie
 
Registered: May 2010
Distribution: Linux Mint 8 - Gnome
Posts: 22

Rep: Reputation: 15
C++ compiler(G++) comes up with error when I try to compile a program using Qt.


I am using the C++ compiler G++ to compile my programs on Linux Mint 8 - Gnome. I recently installed QT and when I tried to compile a simple "Hello World!" program it gave me this error:

Quote:
mint@mint ~ $ g++ HelloWorldQt.cpp -I /usr/include/qt4/ -o HelloWorld!
/tmp/cc1oEaHl.o: In function `main':
HelloWorldQt.cpp: (.text+0x2a): undefined reference to `QApplication::QApplication(int&, char**, int)'
HelloWorldQt.cpp: (.text+0x53): undefined reference to `QPushButton::QPushButton(QString const&, QWidget*)'
HelloWorldQt.cpp: (.text+0xa1): undefined reference to `QApplication::exec()'
HelloWorldQt.cpp: (.text+0xaf): undefined reference to `QPushButton::~QPushButton()'
HelloWorldQt.cpp: (.text+0xc2): undefined reference to `QPushButton::~QPushButton()'
HelloWorldQt.cpp: (.text+0xd6): undefined reference to `QApplication::~QApplication()'
HelloWorldQt.cpp: (.text+0xf2): undefined reference to `QApplication::~QApplication()'
/tmp/cc1oEaHl.o: In function `QString::QString(char const*)':
HelloWorldQt.cpp: (.text._ZN7QStringC1EPKc[QString::QString(char const*)]+0x1d): undefined reference to `QString::fromAscii_helper(char const*, int)'
/tmp/cc1oEaHl.o: In function `QString::~QString()':
HelloWorldQt.cpp: (.text._ZN7QStringD1Ev[QString::~QString()]+0x2d): undefined reference to `QString::free(QString:ata*)'
/tmp/cc1oEaHl.o: In function `QWidget::resize(int, int)':
HelloWorldQt.cpp: (.text._ZN7QWidget6resizeEii[QWidget::resize(int, int)]+0x35): undefined reference to `QWidget::resize(QSize const&)'
collect2: ld returned 1 exit status
mint@mint ~ $
This is the code in HelloWorldQt.cpp:

Code:
#include <QtGui/QApplication>
#include <QtGui/QPushButton>

int main(int argc, char *argv[])
{
	QApplication app(argc, argv);

	QPushButton hello("Hello world!");
	hello.resize(100, 30);

	hello.show();
	return app.exec();
}
I have tried using GTK instead but I get a similar error.
If anyone knows why this is happening or how to fix it, your help would be greatly appreciated. Thanx!
 
Old 05-26-2010, 01:16 PM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Those seem to be linker errors. Why don't you just use qmake to generate a makefile and then run make to build the program (this might not be the correct sequence of commands, because I can't remember). See the Qt documentation..
 
Old 05-26-2010, 01:21 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,234

Rep: Reputation: 180Reputation: 180
Try adding -lgtk to the end of the command line.
 
Old 05-26-2010, 10:14 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
As Nylex suggested you need to use qmake. The documentation is quite good and qmake is fairly easy to learn.
 
Old 05-27-2010, 12:37 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by smeezekitty View Post
Try adding -lgtk to the end of the command line.
Again, for GTK read the documentation: http://library.gnome.org/devel/gtk-t...able/x111.html
 
Old 05-27-2010, 12:57 AM   #6
mac.tieu
Member
 
Registered: Jan 2010
Location: Vietnam
Distribution: Arch
Posts: 65

Rep: Reputation: 22
You should create a HelloWorldQt.pro in source directory like this:
Code:
TARGET = HelloWorldQt
TEMPLATE = app
SOURCES += HelloWorldQt.cpp
Run qmake to create Makefile
Code:
qmake
make to create target application
Code:
make
MT
 
Old 05-27-2010, 01:59 AM   #7
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
I think if you run "qmake -project" it generates the project file for you.
 
Old 05-27-2010, 11:28 AM   #8
rohedin
LQ Newbie
 
Registered: May 2010
Distribution: Linux Mint 8 - Gnome
Posts: 22

Original Poster
Rep: Reputation: 15
Talking Thanx! :D

Thank you so much, everyone who posted a response!
Especially mac.tieu for your clear and helpful instructions!
With your help I got my first QT program to compile and run successfully. I hope this post is useful to other people who might have the same problem

Thanx and Bye!
 
  


Reply

Tags
c++, error, g++, qt, references, undefined


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to Compile Software Package. C compiler cannot create executables * Error Msg* Ciik13 Programming 6 09-25-2009 12:38 AM
Old C program gives error only on new compiler davidstvz Programming 6 02-11-2009 11:43 AM
How to tell digitalmars compiler compile program for DOS? cigarstub Programming 1 04-04-2007 09:15 PM
Qt program: compile error creolophus Programming 2 08-24-2006 03:53 PM
gcc: Internal compiler error: program cc1 got fatal signal 11 smj Linux - Software 2 02-20-2003 11:35 AM


All times are GMT -5. The time now is 09:32 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration