从官方文档里拷下来了一段“Helloworld”的代码:
- #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();
- }
保存为main.cpp,然后用qmake -project
qmake
来生成makefile,这两步都没有报错
但是在make的时候出错了:
- [root@tju-cch qt]# make
- g++ -c -pipe -Wall -W -O2 -g -pipe -D_FORTIFY_SOURCE=2 -m32 -march=i686 -mcpu=i686 -mtune=i686 -DQT_NO_DEBUG -I/usr/lib/qt-3.3/mkspecs/default -I. -I. -I/usr/lib/qt-3.3/include -o main.o main.cpp
- g++ -o qt main.o -L/usr/X11R6/lib -lXext -lX11 -lm
- main.o: In function `main':
- /home/chwoozy/qt/main.cpp:7: undefined reference to `QApplication::QApplication(int&, char**)'
- /home/chwoozy/qt/main.cpp:9: undefined reference to `QString::QString(char const*)'
- /home/chwoozy/qt/main.cpp:9: undefined reference to `QPushButton::QPushButton(QString const&, QWidget*, char const*)'
- main.o: In function `main':
- /usr/lib/qt-3.3/include/qstring.h:847: undefined reference to `QString::shared_null'
- /usr/lib/qt-3.3/include/qstring.h:848: undefined reference to `QStringData::deleteSelf()'
- main.o: In function `main':
- /home/chwoozy/qt/main.cpp:10: undefined reference to `QPushButton::resize(int, int)'
- /home/chwoozy/qt/main.cpp:12: undefined reference to `QApplication::setMainWidget(QWidget*)'
- /home/chwoozy/qt/main.cpp:13: undefined reference to `QWidget::show()'
- /home/chwoozy/qt/main.cpp:14: undefined reference to `QApplication::exec()'
- /home/chwoozy/qt/main.cpp:14: undefined reference to `QPushButton::~QPushButton()'
- /home/chwoozy/qt/main.cpp:14: undefined reference to `QApplication::~QApplication()'
- main.o: In function `main':
- /usr/lib/qt-3.3/include/qstring.h:847: undefined reference to `QString::shared_null'
- /usr/lib/qt-3.3/include/qstring.h:848: undefined reference to `QStringData::deleteSelf()'
- main.o: In function `main':
- /home/chwoozy/qt/main.cpp:14: undefined reference to `QApplication::~QApplication()'
- /home/chwoozy/qt/main.cpp:14: 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] 错误 1
不知道是哪里出错了?
我用的是MagicLinux2.0正式版里面自带的Qt3.3.6
[ 此贴被chwoozy在2006-04-09 17:32重新编辑 ]