You are not logged in.
Pages: 1
Hi!
I want to learn qt library and I've got a problem at the very beginning - when I want to compile simple helloworld program from qt tutorial:
#include <qapplication>
#include <qpushbutton>
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();
}
I'm getting error messages:
$ make
g++ -o qt helloworld.o -L/usr/X11R6/lib -lXext -lX11 -lm
helloworld.o: In function `main':
helloworld.cpp:(.text+0x34): undefined reference to `QApplication::QApplication(int&, char**)'
helloworld.cpp:(.text+0x45): undefined reference to `QString::QString(char const*)'
helloworld.cpp:(.text+0x63): undefined reference to `QPushButton::QPushButton(QString const&, QWidget*, char const*)'
helloworld.cpp:(.text+0x75): undefined reference to `QString::shared_null'
helloworld.cpp:(.text+0x7f): undefined reference to `QStringData::deleteSelf()'
helloworld.cpp:(.text+0x99): undefined reference to `QPushButton::resize(int, int)'
helloworld.cpp:(.text+0xa5): undefined reference to `QApplication::setMainWidget(QWidget*)'
helloworld.cpp:(.text+0xad): undefined reference to `QWidget::show()'
helloworld.cpp:(.text+0xb5): undefined reference to `QApplication::exec()'
helloworld.cpp:(.text+0xbf): undefined reference to `QPushButton::~QPushButton()'
helloworld.cpp:(.text+0xc7): undefined reference to `QApplication::~QApplication()'
helloworld.cpp:(.text+0xf0): undefined reference to `QString::shared_null'
helloworld.cpp:(.text+0xfa): undefined reference to `QStringData::deleteSelf()'
helloworld.cpp:(.text+0x102): undefined reference to `QApplication::~QApplication()'
helloworld.cpp:(.text+0x118): undefined reference to `QPushButton::~QPushButton()'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0xc): undefined reference to `QGList::clear()'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x10): undefined reference to `QGList::~QGList()'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x14): undefined reference to `QGList::~QGList()'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x18): undefined reference to `QPtrCollection::newItem(void*)'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x20): undefined reference to `QGList::compareItems(void*, void*)'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x24): undefined reference to `QGList::read(QDataStream&, void*&)'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x28): undefined reference to `QGList::write(QDataStream&, void*) const'
helloworld.o:(.rodata._ZTI6QGList[typeinfo for QGList]+0x8): undefined reference to `typeinfo for QPtrCollection'
collect2: ld returned 1 exit status
make: *** [qt] Błąd 1
How can I fix it?
Qt version:
$ pacman -Q qt
qt 3.3.6-4
$ pacman -Q qt-doc
qt-doc 3.3.6-1
Offline
sounds like you aren't linking the QT lib's when you're compiling.
Offline
You'll have to add the QT directory to the list of directories g++ searches. Use the -I flag (probably -I/opt/qt/include).
Or use qmake, it might be better.
Offline
Using qmake:
[puszczyk@ordo qt]$ ls
helloworld.cpp
[puszczyk@ordo qt]$ qmake -project
[puszczyk@ordo qt]$ qmake
[puszczyk@ordo qt]$ make
g++ -c -pipe -Wall -W -march=i686 -O2 -pipe -DQT_NO_DEBUG -I/opt/qt/mkspecs/linux-g++ -I. -I. -I/opt/qt/include -o helloworld.o helloworld.cpp
g++ -o qt helloworld.o -L/usr/X11R6/lib -lXext -lX11 -lm
helloworld.o: In function `main':
helloworld.cpp:(.text+0x34): undefined reference to `QApplication::QApplication(int&, char**)'
helloworld.cpp:(.text+0x45): undefined reference to `QString::QString(char const*)'
helloworld.cpp:(.text+0x63): undefined reference to `QPushButton::QPushButton(QString const&, QWidget*, char const*)'
helloworld.cpp:(.text+0x75): undefined reference to `QString::shared_null'
helloworld.cpp:(.text+0x7f): undefined reference to `QStringData::deleteSelf()'
helloworld.cpp:(.text+0x99): undefined reference to `QPushButton::resize(int, int)'
helloworld.cpp:(.text+0xa5): undefined reference to `QApplication::setMainWidget(QWidget*)'
helloworld.cpp:(.text+0xad): undefined reference to `QWidget::show()'
helloworld.cpp:(.text+0xb5): undefined reference to `QApplication::exec()'
helloworld.cpp:(.text+0xbf): undefined reference to `QPushButton::~QPushButton()'
helloworld.cpp:(.text+0xc7): undefined reference to `QApplication::~QApplication()'
helloworld.cpp:(.text+0xf0): undefined reference to `QString::shared_null'
helloworld.cpp:(.text+0xfa): undefined reference to `QStringData::deleteSelf()'
helloworld.cpp:(.text+0x102): undefined reference to `QApplication::~QApplication()'
helloworld.cpp:(.text+0x118): undefined reference to `QPushButton::~QPushButton()'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0xc): undefined reference to `QGList::clear()'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x10): undefined reference to `QGList::~QGList()'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x14): undefined reference to `QGList::~QGList()'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x18): undefined reference to `QPtrCollection::newItem(void*)'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x20): undefined reference to `QGList::compareItems(void*, void*)'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x24): undefined reference to `QGList::read(QDataStream&, void*&)'
helloworld.o:(.rodata._ZTV6QGList[vtable for QGList]+0x28): undefined reference to `QGList::write(QDataStream&, void*) const'
helloworld.o:(.rodata._ZTI6QGList[typeinfo for QGList]+0x8): undefined reference to `typeinfo for QPtrCollection'
collect2: ld returned 1 exit status
make: *** [qt] Błąd 1
[puszczyk@ordo qt]$
Still nothing.
Nevertheless, thanks for Your replies.
Offline
change directory name to something else than qt
Offline
Pages: 1