• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

[gelöst]Qt/C++:Erstes Programm

harvey

Member
Habe eben versucht folgendes Programm zu compilieren:

Code:
#include <qapplication.h>
#include <qlabel.h>

int main( int argc, char* argv[])
{
 QApplication myapp( argc, argv );

 QLabel* mylabel = new QLabel( "Hello world", 0 );
 mylabel->resize( 120, 30 );

 myapp.setMainWidget( mylabel );
 mylabel->show();
 return myapp.exec();
}

Der Compileraufruf erfolgte mit:
Code:
g++ -I/usr/lib/qt3/include -L/usr/lib/qt3/lib -lqt -o hello hello.cpp

Ich erhielt folgende Fehlermeldungen:

Code:
/tmp/ccQUHyrT.o: In function `main':
hello.cpp:(.text+0x24): undefined reference to `QApplication::QApplicatio
n(int&, char**)'
hello.cpp:(.text+0x37): undefined reference to `QString::QString(char con
st*)'
hello.cpp:(.text+0x76): undefined reference to `QLabel::QLabel(QString co
nst&, QWidget*, char const*, unsigned int)'
hello.cpp:(.text+0xeb): undefined reference to `QApplication::setMainWidg
et(QWidget*)'
hello.cpp:(.text+0x10a): undefined reference to `QApplication::exec()'
hello.cpp:(.text+0x117): undefined reference to `QApplication::~QApplicat
ion()'
hello.cpp:(.text+0x12d): undefined reference to `QApplication::~QApplicat
ion()'
/tmp/ccQUHyrT.o: In function `QString::~QString()':
hello.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x1d): undefined re
ference to `QString::shared_null'
hello.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x2e): undefined re
ference to `QStringData::deleteSelf()'
/tmp/ccQUHyrT.o:(.rodata._ZTV6QGList[vtable for QGList]+0xc): undefined r                               eference to `QGList::clear()'
/tmp/ccQUHyrT.o:(.rodata._ZTV6QGList[vtable for QGList]+0x10): undefined                                reference to `QGList::~QGList()'
/tmp/ccQUHyrT.o:(.rodata._ZTV6QGList[vtable for QGList]+0x14): undefined                                reference to `QGList::~QGList()'
/tmp/ccQUHyrT.o:(.rodata._ZTV6QGList[vtable for QGList]+0x18): undefined                                reference to `QPtrCollection::newItem(void*)'
/tmp/ccQUHyrT.o:(.rodata._ZTV6QGList[vtable for QGList]+0x20): undefined                                reference to `QGList::compareItems(void*, void*)'
/tmp/ccQUHyrT.o:(.rodata._ZTV6QGList[vtable for QGList]+0x24): undefined                                reference to `QGList::read(QDataStream&, void*&)'
/tmp/ccQUHyrT.o:(.rodata._ZTV6QGList[vtable for QGList]+0x28): undefined                                reference to `QGList::write(QDataStream&, void*) const'
/tmp/ccQUHyrT.o:(.rodata._ZTI6QGList[typeinfo for QGList]+0x8): undefined                                reference to `typeinfo for QPtrCollection'
collect2: ld gab 1 als Ende-Status zurück

Was habe ich vergessen/falsch gemacht?
 

Anubid

Hacker
Falls du QT4 nuzt:
Du kannst auch qmake nutzen, das ist praktisch für größere Sachen:
Code:
qmake -project
[Dann evtl dir .pro Datei anpassen. In der QT4-Doku steht alles Dokumentiert.]
qmake -makefile
make
Wenn du nur was an Code geändert hast, reicht ein einfaches make aus um es zu kompilieren.
 
Oben