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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-26-2010, 12:01 PM
|
#1
|
|
LQ Newbie
Registered: May 2010
Distribution: Linux Mint 8 - Gnome
Posts: 22
Rep:
|
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!
|
|
|
|
05-26-2010, 12:16 PM
|
#2
|
|
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,466
Rep: 
|
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..
|
|
|
|
05-26-2010, 12:21 PM
|
#3
|
|
Senior Member
Registered: Sep 2009
Location: Washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 2,136
Rep: 
|
Try adding -lgtk to the end of the command line.
|
|
|
|
05-26-2010, 09:14 PM
|
#4
|
|
Senior Member
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,375
Rep: 
|
As Nylex suggested you need to use qmake. The documentation is quite good and qmake is fairly easy to learn.
|
|
|
|
05-26-2010, 11:37 PM
|
#5
|
|
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,466
Rep: 
|
Quote:
Originally Posted by smeezekitty
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
|
|
|
|
05-26-2010, 11:57 PM
|
#6
|
|
Member
Registered: Jan 2010
Location: Vietnam
Distribution: Arch
Posts: 65
Rep:
|
You should create a HelloWorldQt.pro in source directory like this:
Code:
TARGET = HelloWorldQt
TEMPLATE = app
SOURCES += HelloWorldQt.cpp
Run qmake to create Makefile
make to create target application
MT
|
|
|
|
05-27-2010, 12:59 AM
|
#7
|
|
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,466
Rep: 
|
I think if you run "qmake -project" it generates the project file for you.
|
|
|
|
05-27-2010, 10:28 AM
|
#8
|
|
LQ Newbie
Registered: May 2010
Distribution: Linux Mint 8 - Gnome
Posts: 22
Original Poster
Rep:
|
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! 
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:15 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|