LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 678|回复: 7

simple question about compiling

[复制链接]
发表于 2004-7-24 11:52:15 | 显示全部楼层 |阅读模式
I am a humble beginner on qt.
Recently, I follow the tutorail,
http://www.qiliang.net/qt/tutorial1-01.html
copy the code
#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();
}
in a *.txt and save it as main.cpp
copy the file main.cpp to /usr/bin where the executable  file qmake
lived.
then qmake -project
but no *.pro file in the folder /usr/bin.
why?
thank you.
my email:liouxiangbiao@yahoo.com.cn
发表于 2004-7-24 19:30:12 | 显示全部楼层
why do you copy main.cpp to /usr/bin? This directory is supposed to hold binary executive files.
Anyway, ensure you have installed QT, and $QTDIR/bin have been  included in shell variable PATH.
 楼主| 发表于 2004-7-24 21:05:12 | 显示全部楼层
thank you, the file qt.pro has come up.
but a new problem appear when I try to make

[root@localhost qt]# qmake -project
[root@localhost qt]# qmake
[root@localhost qt]# ls
main.cpp  Makefile  qt.pro
[root@localhost qt]# make
g++ -c -pipe -Wall -W -O2 -g -pipe -march=i386 -mcpu=i686 -fno-use-cxa-atexit -fno-exceptions -DQT_NO_DEBUG  -I/usr/lib/qt-3.1/mkspecs/default -I. -I. -I/usr/lib/qt-3.1/include -o main.o main.cpp
g++  -o qt main.o   -L/usr/X11R6/lib -lXext -lX11 -lm
main.o(.text+0x2c): In function `main':
/hda07_freedom/creation/c++_fb/qt/main.cpp:14: undefined reference to `QApplication:Application[in-charge](int&, char**)'
main.o(.text+0x3d):/hda07_freedom/creation/c++_fb/qt/main.cpp:16: undefined reference to `QString:String[in-charge](char const*)'
main.o(.text+0x59):/hda07_freedom/creation/c++_fb/qt/main.cpp:16: undefined reference to `QPushButton:PushButton[in-charge](QString const&, QWidget*, char const*)'
main.o(.text+0x6e): In function `main':
/usr/lib/qt-3.1/include/qstring.h:770: undefined reference to `QString::shared_null'
main.o(.text+0x78):/usr/lib/qt-3.1/include/qstring.h:771: undefined reference to `QStringData::deleteSelf()'
main.o(.text+0x96): In function `main':
/hda07_freedom/creation/c++_fb/qt/main.cpp:17: undefined reference to `QPushButton::resize(int, int)'
main.o(.text+0xa2):/hda07_freedom/creation/c++_fb/qt/main.cpp:19: undefined reference to `QApplication::setMainWidget(QWidget*)'
main.o(.text+0xaa):/hda07_freedom/creation/c++_fb/qt/main.cpp:20: undefined reference to `QWidget::show()'
main.o(.text+0xb2):/hda07_freedom/creation/c++_fb/qt/main.cpp:21: undefined reference to `QApplication::exec()'
main.o(.text+0xbc):/hda07_freedom/creation/c++_fb/qt/main.cpp:21: undefined reference to `QPushButton::~QPushButton [in-charge]()'
main.o(.text+0xc4):/hda07_freedom/creation/c++_fb/qt/main.cpp:21: undefined reference to `QApplication::~QApplication [in-charge]()'
main.o(.gnu.linkonce.r._ZTV6QGList+0xc): In function `main':
/usr/lib/qt-3.1/include/qglist.h:147: undefined reference to `QGList::clear()'
main.o(.gnu.linkonce.r._ZTV6QGList+0x10):/usr/lib/qt-3.1/include/qglist.h:147: undefined reference to `QGList::~QGList [in-charge]()'
main.o(.gnu.linkonce.r._ZTV6QGList+0x14): In function `main':
/hda07_freedom/creation/c++_fb/qt/main.cpp:16: undefined reference to `QGList::~QGList [in-charge deleting]()'
main.o(.gnu.linkonce.r._ZTV6QGList+0x18):/hda07_freedom/creation/c++_fb/qt/main.cpp:14: undefined reference to `QPtrCollection::newItem(void*)'
main.o(.gnu.linkonce.r._ZTV6QGList+0x20):/hda07_freedom/creation/c++_fb/qt/main.cpp:14: undefined reference to `QGList::compareItems(void*, void*)'
main.o(.gnu.linkonce.r._ZTV6QGList+0x24):/hda07_freedom/creation/c++_fb/qt/main.cpp:14: undefined reference to `QGList::read(QDataStream&, void*&)'
main.o(.gnu.linkonce.r._ZTV6QGList+0x28):/hda07_freedom/creation/c++_fb/qt/main.cpp:14: undefined reference to `QGList::write(QDataStream&, void*) const'
main.o(.gnu.linkonce.r._ZTI6QGList+0x8):/hda07_freedom/creation/c++_fb/qt/main.cpp:16: undefined reference to `typeinfo for QPtrCollection'
collect2: ld returned 1 exit status
make: *** [qt] Error 1
[root@localhost qt]#

what is wrong?
thank you.
发表于 2004-7-25 08:32:11 | 显示全部楼层
g++ -o qt main.o -L/usr/X11R6/lib -lXext -lX11 -lm

这一句里面怎么没有-lqt呀?
 楼主| 发表于 2004-7-25 10:42:45 | 显示全部楼层
这个我不清楚啊。
输入make系统就出现了这些信息。
一些库文件也有:
[root@localhost lib]# pwd
/usr/lib/qt-3.1/lib
[root@localhost lib]# ls
libdesigner.a          libqt-mt.so      libqt-mt.so.3.1.2  libqt.so.3.1    libqui.so.1
libeditor.a            libqt-mt.so.3    libqt.so           libqt.so.3.1.2  libqui.so.1.0
libqassistantclient.a  libqt-mt.so.3.1  libqt.so.3         libqui.so       libqui.so.1.0.0
[root@localhost lib]#
 楼主| 发表于 2004-7-25 11:59:37 | 显示全部楼层
原来/usr/X11R6/lib没有这些库文件,
我把/usr/lib/qt-3.1/lib里的所有文件复制到/usr/X11R6/lib
然后手动g++.
g++ -c -pipe -Wall -W -O2 -g -pipe -march=i386 -mcpu=i686 -fno-use-cxa-atexit -fno-exceptions -DQT_NO_DEBUG -I/usr/lib/qt-3.1/mkspecs/default -I. -I. -I/usr/lib/qt-3.1/include -o main.o main.cpp
然后:
g++ -o qt main.o -L/usr/X11R6/lib -lqt -lXext -lX11 -lm
问题就解决了。
我不清楚这是怎么回事,
不过欣慰的是最后不是出来窗口了。
http://www.fbuilder.com/tem/qt_a.png
thank you.
发表于 2004-7-25 19:24:11 | 显示全部楼层
最初由 Xiangbuilder 发表
原来/usr/X11R6/lib没有这些库文件,
我把/usr/lib/qt-3.1/lib里的所有文件复制到/usr/X11R6/lib

昏!直接用-L/usr/lib/qt-3.1/lib指定一下路径不就行了,有必要把qt的库文件和Xwindow的库文件混在一下起吗?
 楼主| 发表于 2004-7-26 02:41:50 | 显示全部楼层
我不清楚这个,所以乱搞的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表