LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Compile QT get Undefined reference (http://www.linuxquestions.org/questions/linux-general-1/compile-qt-get-undefined-reference-277677/)

jordban 01-14-2005 07:24 AM

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

omes 01-15-2005 04:09 AM

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

__J 01-15-2005 04:40 AM

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?

omes 01-15-2005 04:46 AM

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

- omes

__J 01-15-2005 05:03 AM

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.

omes 01-15-2005 05:05 AM

qt: /usr/lib/qt

__J 01-15-2005 05:08 AM

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).

omes 01-15-2005 05:10 AM

it's the original slackware package. I'm going to install it myself now.

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

__J 01-15-2005 05:11 AM

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).

omes 01-15-2005 05:17 AM

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...

__J 01-15-2005 05:19 AM

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?

omes 01-15-2005 08:28 AM

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.

omes 01-15-2005 08:45 AM

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

- omes

__J 01-15-2005 06:53 PM

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.

omes 01-15-2005 06:58 PM

ok, ill try this first ting in the morning. :)

- omes


All times are GMT -5. The time now is 06:52 AM.