LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-14-2005, 07:24 AM   #1
jordban
LQ Newbie
 
Registered: Dec 2004
Posts: 19

Rep: Reputation: 0
Compile QT get Undefined reference


Hello,
I got finally QT installed and im working on a test copmile to make sure everything is working.
First i have a main.cpp which contains
Code:
#include <qapplication.h>
#include <qpushbutton.h>

int main( int argc, char **argv )
{
    QApplication a( argc, argv );

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

    a.setMainWidget( &hello );
    hello.show();
    return a.exec();
}
Next i type in qmake -project to build a .pro project file, then i trype in qmake to make a makefile. Finally i type in make to compile the project but i get back these errors
Code:
g++ -c -pipe -Wall -W -O2 -DQT_NO_DEBUG  -I/home/jordan/qt3/mkspecs/linux-g++ -I. -I. -I/home/jordan/qt3/include -o main.o main.cpp
g++  -o qt main.o    -L/usr/X11R6/lib -lXext -lX11 -lm
main.o(.text+0x1e): In function `main':
: undefined reference to `QApplication::QApplication(int&, char**)'
main.o(.text+0x31): In function `main':
: undefined reference to `QString::QString(char const*)'
main.o(.text+0x45): In function `main':
: undefined reference to `QPushButton::QPushButton(QString const&, QWidget*, char const*)'
main.o(.text+0x5d): In function `main':
: undefined reference to `QString::shared_null'
main.o(.text+0x68): In function `main':
: undefined reference to `QStringData::deleteSelf()'
main.o(.text+0x77): In function `main':
: undefined reference to `QPushButton::resize(int, int)'
main.o(.text+0x80): In function `main':
: undefined reference to `QApplication::setMainWidget(QWidget*)'
main.o(.text+0x88): In function `main':
: undefined reference to `QWidget::show()'
main.o(.text+0x90): In function `main':
: undefined reference to `QApplication::exec()'
main.o(.text+0x9b): In function `main':
: undefined reference to `QPushButton::~QPushButton()'
main.o(.text+0xa3): In function `main':
: undefined reference to `QApplication::~QApplication()'
main.o(.text+0xc7): In function `main':
: undefined reference to `QString::shared_null'
main.o(.text+0xd2): In function `main':
: undefined reference to `QStringData::deleteSelf()'
main.o(.text+0xe3): In function `main':
: undefined reference to `QApplication::~QApplication()'
main.o(.text+0xf7): In function `main':
: undefined reference to `QPushButton::~QPushButton()'
main.o(.gnu.linkonce.r._ZTV6QGList+0xc): undefined reference to `QGList::clear()'
main.o(.gnu.linkonce.r._ZTV6QGList+0x10): undefined reference to `QGList::~QGList()'
main.o(.gnu.linkonce.r._ZTV6QGList+0x14): undefined reference to `QGList::~QGList()'
main.o(.gnu.linkonce.r._ZTV6QGList+0x18): undefined reference to `QPtrCollection::newItem(void*)'
main.o(.gnu.linkonce.r._ZTV6QGList+0x20): undefined reference to `QGList::compareItems(void*, void*)'
main.o(.gnu.linkonce.r._ZTV6QGList+0x24): undefined reference to `QGList::read(QDataStream&, void*&)'
main.o(.gnu.linkonce.r._ZTV6QGList+0x28): undefined reference to `QGList::write(QDataStream&, void*) const'
main.o(.gnu.linkonce.r._ZTI6QGList+0x8): undefined reference to `typeinfo for QPtrCollection'
collect2: ld returned 1 exit status
make: *** [qt] Error 1
Iv done many searches and i cant figure out why this wont work.

Thanks in advance,
jordan
 
Old 01-15-2005, 04:09 AM   #2
omes
Member
 
Registered: Jan 2003
Distribution: debian, FreeBSD
Posts: 120

Rep: Reputation: 15
Hi.

First i must say i know nether Qt nor c++, and you should have postet this is programming(because most people there can answer much better than i do.)
It looks like it's something wrong with your code. Try to just compile some code from a tutorial, and see if it works..

Good luck

- omes
 
Old 01-15-2005, 04:40 AM   #3
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
The code looks ok, looks like qmake isnt finding the libs it needs. is $QTDIR/lib in /etc/ld.so.conf and have you run ldconfig since? also is $QTDIR set to the root of the qt installation?

Last edited by __J; 01-15-2005 at 04:42 AM.
 
Old 01-15-2005, 04:46 AM   #4
omes
Member
 
Registered: Jan 2003
Distribution: debian, FreeBSD
Posts: 120

Rep: Reputation: 15
__J: I have everything properly installed, and i get the same errors as the threadstarter..

- omes
 
Old 01-15-2005, 05:03 AM   #5
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
Omes, where do you have qt installed?

jordban, make sure /home/jordban/qt3/lib is in your LD_LIBRARY_PATH

I entered the code and it compiled fine on my machine (with qt-3.3.3).

you should see it linking with qt ( -lqt-mt ) in the linking output. If you look at jordban's post above, it never links with it.

Last edited by __J; 01-15-2005 at 05:05 AM.
 
Old 01-15-2005, 05:05 AM   #6
omes
Member
 
Registered: Jan 2003
Distribution: debian, FreeBSD
Posts: 120

Rep: Reputation: 15
qt: /usr/lib/qt
 
Old 01-15-2005, 05:08 AM   #7
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
did you compile it yourself or is it the original slack package. check /etc/profile.d/ for qt.sh and make sure /usr/lib/qt3/lib is in /etc/ld.so.conf ( the slack package should have taken care of this for you).
 
Old 01-15-2005, 05:10 AM   #8
omes
Member
 
Registered: Jan 2003
Distribution: debian, FreeBSD
Posts: 120

Rep: Reputation: 15
it's the original slackware package. I'm going to install it myself now.

btw, there was no /usr/lib/qt3/lib in it

Last edited by omes; 01-15-2005 at 05:12 AM.
 
Old 01-15-2005, 05:11 AM   #9
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
double check for the two things mentioned above and try it again ( I'm using the slack 10 package and after qmake -project, qmake, make it compiled and linked without a problem).
 
Old 01-15-2005, 05:17 AM   #10
omes
Member
 
Registered: Jan 2003
Distribution: debian, FreeBSD
Posts: 120

Rep: Reputation: 15
I don't have qt3 installed..
Guess that *might* be the threadstartes problem as well. As we get the exact same output when we try to compile to program...
 
Old 01-15-2005, 05:19 AM   #11
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
looks like he compiled it himself because its picking up the includes and compiles but fails at the linking stage. Also jordban, if you compiled it yourself did you include thread support?
 
Old 01-15-2005, 08:28 AM   #12
omes
Member
 
Registered: Jan 2003
Distribution: debian, FreeBSD
Posts: 120

Rep: Reputation: 15
I've compiled it myself with thread support. I've checked up on the things you've said. I'm catching the package from slackware.com now.
 
Old 01-15-2005, 08:45 AM   #13
omes
Member
 
Registered: Jan 2003
Distribution: debian, FreeBSD
Posts: 120

Rep: Reputation: 15
i didn't get it to work properly even with the slackware version of qt3..

- omes
 
Old 01-15-2005, 06:53 PM   #14
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
wait, did you compile it or install the slackware package?
If compiling, it has to be done a certain way (its not a standard ./configure,make, and make install) as for the standard slackware package, it sets up the environmental variables and library link paths for you so you shouldn't have many problems with that. Just for reference, here's how I compile qt:


export QTDIR=$PWD
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export PATH=$QTDIR/bin:$PATH

./configure -prefix /opt/qt-3.3.3 -qt-gif -system-libjpeg -system-zlib -system-libpng -system-libmng -thread -no-exceptions

make ( or make sub-tools if you don't want the examples and such)
checkinstall (to make a slack package)

after its finished add:

/opt/qt-3.3.3/lib

to /etc/ld.so.conf

and open /etc/profile with a text editor and add the following line:

export QTDIR=/opt/qt-3.3.3

save and exit, then log out and back in (or source /etc/profile) and you shouldn't have any problems.

But the slack package is the easiest way to go by far.
 
Old 01-15-2005, 06:58 PM   #15
omes
Member
 
Registered: Jan 2003
Distribution: debian, FreeBSD
Posts: 120

Rep: Reputation: 15
ok, ill try this first ting in the morning.

- omes
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined reference, why? george_mercury Programming 4 05-07-2009 12:15 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 03:01 AM
undefined reference mp4-10 Programming 3 01-25-2005 12:38 PM
2.6-test9 compile problem - undefined reference to `ide_hwifs' saint Linux - General 5 11-20-2003 04:53 PM
ncurses compile error: "undefined reference" Mr. Eek Linux From Scratch 1 05-12-2003 04:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration