PDA

View Full Version : Qt3: Unable to find library functions



rhb
January 20th, 2007, 09:41 PM
I am trying to build a simple qt tutorial program, and I get a bunch of undefined library functions. I originally typed in the program using Qt Designer. I renamed the program main.cpp and cleaned out the directory just before running this test:


rhb@linuxdualboot:~/wip/qt$ vdir
total 4
-rw-r--r-- 1 rhb rhb 572 2007-01-20 14:01 main.cpp

rhb@linuxdualboot:~/wip/qt$ cat main.cpp
#include <qapplication.h>
#include <qpushbutton.h>

// this start out as a program with a
// very simple GUI interface, easier
// to build programatically than
// with the QT designer

int main( int argc, char **argv )
{
QApplication a( argc, argv); // create app object
QPushButton hello( "Hello, World", 0 ); // a simple GUI widget with no parent
hello.resize( 100, 30); // set it's size

a.setMainWidget( &hello ); // the 'button' is the main 'Window' of the app
hello.show(); // display it
a.exec(); // enable interaction

}


rhb@linuxdualboot:~/wip/qt$ qmake -project
rhb@linuxdualboot:~/wip/qt$ qmake
rhb@linuxdualboot:~/wip/qt$ vdir
total 12
-rw-r--r-- 1 rhb rhb 572 2007-01-20 14:01 main.cpp
-rw-r--r-- 1 rhb rhb 2595 2007-01-20 14:03 Makefile
-rw-r--r-- 1 rhb rhb 286 2007-01-20 14:03 qt.pro
rhb@linuxdualboot:~/wip/qt$ cat M*

<Makefile omitted, looked reasonable>

rhb@linuxdualboot:~/wip/qt$ cat q*
################################################## ####################
# Automatically generated by qmake (1.07a) Sat Jan 20 14:03:35 2007
################################################## ####################

TEMPLATE = app
CONFIG -= moc
INCLUDEPATH += .

# Input
SOURCES += main.cpp

rhb@linuxdualboot:~/wip/qt$ make
g++ -c -pipe -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I. -I/usr/include/qt3 -o main.o main.cpp
g++ -o qt main.o -L/usr/X11R6/lib -lXext -lX11 -lm -lpthread
main.o: In function `main':main.cpp:(.text+0x27): undefined reference to `QApplication::QApplication(int&, char**)'
:main.cpp:(.text+0x3a): undefined reference to `QString::QString(char const*)'
:main.cpp:(.text+0x5c): undefined reference to `QPushButton::QPushButton(QString const&, QWidget*, char const*)'
:main.cpp:(.text+0x70): undefined reference to `QString::shared_null'
:main.cpp:(.text+0x7a): undefined reference to `QStringData::deleteSelf()'
:main.cpp:(.text+0x92): undefined reference to `QPushButton::resize(int, int)'
:main.cpp:(.text+0x9e): undefined reference to `QApplication::setMainWidget(QWidget*)'
:main.cpp:(.text+0xa6): undefined reference to `QWidget::show()'
:main.cpp:(.text+0xae): undefined reference to `QApplication::exec()'
:main.cpp:(.text+0xb6): undefined reference to `QPushButton::~QPushButton()'
:main.cpp:(.text+0xbe): undefined reference to `QApplication::~QApplication()'
:main.cpp:(.text+0xde): undefined reference to `QString::shared_null'
:main.cpp:(.text+0xe8): undefined reference to `QStringData::deleteSelf()'
:main.cpp:(.text+0xf0): undefined reference to `QApplication::~QApplication()'
:main.cpp:(.text+0x106): undefined reference to `QPushButton::~QPushButton()'
main.o:(.gnu.linkonce.r._ZTI6QGList[typeinfo for QGList]+0x8): undefined reference to `typeinfo for QPtrCollection'
main.o:(.gnu.linkonce.r._ZTV6QGList[vtable for QGList]+0xc): undefined reference to `QGList::clear()'
main.o:(.gnu.linkonce.r._ZTV6QGList[vtable for QGList]+0x10): undefined reference to `QGList::~QGList()'
main.o:(.gnu.linkonce.r._ZTV6QGList[vtable for QGList]+0x14): undefined reference to `QGList::~QGList()'
main.o:(.gnu.linkonce.r._ZTV6QGList[vtable for QGList]+0x18): undefined reference to `QPtrCollection::newItem(void*)'
main.o:(.gnu.linkonce.r._ZTV6QGList[vtable for QGList]+0x20): undefined reference to `QGList::compareItems(void*, void*)'
main.o:(.gnu.linkonce.r._ZTV6QGList[vtable for QGList]+0x24): undefined reference to `QGList::read(QDataStream&, void*&)'
main.o:(.gnu.linkonce.r._ZTV6QGList[vtable for QGList]+0x28): undefined reference to `QGList::write(QDataStream&, void*) const'
collect2: ld returned 1 exit status
make: *** [qt] Error 1
rhb@linuxdualboot:~/wip/qt$


I had to use qt3, because qtdesigner would not install with qt4. I have checked that all qt3 and libqt3 devel packages I should need were installed. Maybe I missed one? Maybe I need to specify a library on the linker command? If we can't identify this as a package or installation problem, then I will ask trolltech if they have a possible explanation.

<offtopic>
Maybe this sub-forum should specify that 'missing library' and 'missing header' problems should be posted here, but syntax, functionality, etc. issues should not. I considered posting in main forum because it was my own code that didn't compile, not a working program that I'm trying to build a package for nor a downloaded package. I believe it should be here because it is an installation or configuration issue.
</offtopic>

hod139
January 21st, 2007, 04:10 AM
have you installed libqt4-dev?

rhb
January 21st, 2007, 08:15 AM
I'm fuzzy about the details now, but I believe it required qt >3.0 and <4.0, and refused to install when I first installed qt4 because it was the latest. In any case, it ought to work with the qt3 version. I have removed all qt4 files so as not to have a conflict.

If anyone can tell me how to examine the qt3 and qt4 libraries to see what is and isn't there, I will try that. I could google for specific entry points, but it looks like many are missing, so either my install is inconsistent or the ubuntu package is incomplete.

I see now that there's a qt3-designer and a qt4-designer. If anyone has had success with either of these, let me know. Also, I might try keeping some qt3 and qt4 packages if they don't conflict.

I appreciate your help. I'm beginning to think I can deal with most of the quirks of the pkg mgmt system now, with occasional help from the forum, of course.

hod139
January 21st, 2007, 07:28 PM
For development files you always need to install *-dev packages, as these packages will install the headers and libraries needed for building.

Opening synaptic and searching for "qt3 dev" (without the quotes) shows all packages related to building qt3 applications.

Varadhan
January 9th, 2008, 02:14 PM
Hi,

I too had the same problem and solved it.

create a seperate directory
cp your main.cpp inside and then run the following command

$qmake -project
$qmake
$make

It seems to be problem with qmake if the current directory is qt. I searched lot place but no good. Atlast i got it work.
too late putting it here so that everyone will find it usefull.


FYI

eden:~/Programs/CPP/qt/hello>ls
hello.cpp
eden:~/Programs/CPP/qt/hello>qmake -project
eden:~/Programs/CPP/qt/hello>ls
hello.cpp hello.pro
eden:~/Programs/CPP/qt/hello>qmake
eden:~/Programs/CPP/qt/hello>ls
hello.cpp hello.pro Makefile
eden:~/Programs/CPP/qt/hello>make
g++ -c -pipe -Wall -W -O2 -g -pipe -m32 -march=i386 -DQT_NO_DEBUG -DQT_SHARED -DQT_THREAD_SUPPORT -I/usr/lib/qt-3.3/mkspecs/default -I. -I. -I/usr/lib/qt-3.3/include -I/usr/X11R6/include -o hello.o hello.cpp
g++ -o hello hello.o -L/usr/lib/qt-3.3/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm
eden:~/Programs/CPP/qt/hello>ls
hello* hello.cpp hello.o hello.pro Makefile
eden:~/Programs/CPP/qt/hello>

kevinchkin
October 17th, 2009, 01:02 AM
It seems to be problem with qmake if the current directory is qt. I searched lot place but no good. Atlast i got it work.

Thanks a lot man. It worked perfect