PDA

View Full Version : Linker problem



vels
7th April 2010, 16:16
Hi All,

I am new to Qt, got Qt-4.5 commercial version installed on my SUSE 10.0 box

Now I am doing a feasibility study on compiling qt application by hand and not relying on qmake (its more clumsy and difficult to understand)

In QT installation, under /examples/widgets directory i am trying to build calculator executable sample

Step 1 - Compiling
Compiled the sample using the following compile options
g++ -c -I/usr/local/Trolltech/Qt-4.5.0/mkspecs/linux-g++-64 -I. -I/usr/local/Trolltech/Qt-4.5.0/include/QtCore -I/usr/local/Trolltech/Qt-4.5.0/include/QtGui -I/usr/local/Trolltech/Qt-4.5.0/include -I. calculator.cpp main.cpp button.cpp

Step 2 - Linking
When the object files are linked with Qt libraries I am getting 'undefined references'.
-linker options:
g++ -m64 -Wl,-rpath,/usr/local/Trolltech/Qt-4.5.0/lib -o calculator button.o calculator.o main.o -L/usr/local/Trolltech/Qt-4.5.0/lib -lQtGui -lQtCore -L/usr/X11R6/lib64 -pthread -lpthread

Linker error reported:
button.o: In function `Button::Button(QString const&, QWidget*)':
button.cpp: (.text+0x91): undefined reference to `vtable for Button'
button.cpp: (.text+0x9d): undefined reference to `vtable for Button'
button.o: In function `Button::Button(QString const&, QWidget*)':
button.cpp: (.text+0x113): undefined reference to `vtable for Button'
button.cpp: (.text+0x11f): undefined reference to `vtable for Button'
calculator.o: In function `Calculator::Calculator(QWidget*)':
calculator.cpp: (.text+0x141a): undefined reference to `vtable for Calculator'
calculator.cpp: (.text+0x1429): undefined reference to `vtable for Calculator'
calculator.o: In function `Calculator::Calculator(QWidget*)':
calculator.cpp: (.text+0x256e): undefined reference to `vtable for Calculator'
calculator.cpp: (.text+0x257d): undefined reference to `vtable for Calculator'
calculator.o: In function `Calculator::tr(char const*, char const*)':
calculator.cpp: (.text._ZN10Calculator2trEPKcS1_[Calculator::tr(char const*, char const*)]+0x20): undefined reference to `Calculator::staticMetaObject'
calculator.o: In function `Button* qobject_cast<Button*>(QObject*)':
calculator.cpp: (.text._Z12qobject_castIP6ButtonET_P7QObject[Button* qobject_cast<Button*>(QObject*)]+0x1f): undefined reference to `Button::staticMetaObject'
main.o: In function `Calculator::~Calculator()':
main.cpp: (.text._ZN10CalculatorD1Ev[Calculator::~Calculator()]+0x14): undefined reference to `vtable for Calculator'
main.cpp: (.text._ZN10CalculatorD1Ev[Calculator::~Calculator()]+0x20): undefined reference to `vtable for Calculator'
collect2: ld returned 1 exit status


Can anybody help me ?

Thanks
vels

wysota
7th April 2010, 19:24
Can anybody help me ?

Yes, QMake can ;)

I'd say you forgot to compile and link the file generated by moc (provided you generated it in the first place). That's one of the "clumsyness" and "difficult to understand" things about QMake -- it automates things for you so that you don't have to worry about them. If I were you I would think twice if I really wanted to drop QMake and when I was sure I did, I would think again just to make sure. If I was still convinced that was a good thing to do, I would first learn what QMake did if I wanted to replace it.

vels
8th April 2010, 06:33
Thanks for the reply, i will explore qmake

vels
8th April 2010, 15:07
Hi All,

I got a quick query, is there any way Qmake can be integrated with GNU make? bcz i m planning to use QT as sub system for the main application, where main application will have its own make file and as part of main build Qmake should be performed, since we have moc in Qt is there any better approach to achieve this?

Thanks
vels

wysota
8th April 2010, 15:40
QMake uses make to do its job. QMake can also execute any command you wish, make included.