C++ compiler(G++) comes up with error when I try to compile a program using Qt.
ProgrammingThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 ~ $
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!
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..
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.