• 15760阅读
  • 14回复

【提问】helloworld编译不成功,什么原因 [复制链接]

上一主题 下一主题
离线magicoy
 

只看楼主 倒序阅读 楼主  发表于: 2005-08-28
我真的要疯了.................
代码如下................我编译了N次都不成功.我再用文本编译器写成cpp.再qmake -project再qmake再make
每次都不行.我又重新安装QT 3.3.4还是不行...............都是一样的效果.如果大家不帮我.我活不下去了.....................
---------------------------------------------------------------------------------------------代码如下---------------------
#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();
}

--------------------------------------------------------------------------------------------make时候提示----如下----
[root@MagicLinux Desktop]# ls
MagicLinux miimages qt
[root@MagicLinux Desktop]# cd qt
[root@MagicLinux qt]# qmake -project
[root@MagicLinux qt]# qmake
[root@MagicLinux 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 qtt.o qtt.cpp
g++ -o qt qtt.o   -L/usr/X11R6/lib -lXext -lX11 -lm
qtt.o(.text+0x33): In function `main':
/root/Desktop/qt/qtt.cpp:7: undefined reference to `QApplication::QApplication(int&, char**)'
qtt.o(.text+0x44):/root/Desktop/qt/qtt.cpp:9: undefined reference to `QString::QString(char const*)'
qtt.o(.text+0x62):/root/Desktop/qt/qtt.cpp:9: undefined reference to `QPushButton::QPushButton(QString const&, QWidget*, char const*)'
qtt.o(.text+0x77): In function `main':
/usr/lib/qt-3.3/include/qstring.h:847: undefined reference to `QString::shared_null'
qtt.o(.text+0x81):/usr/lib/qt-3.3/include/qstring.h:848: undefined reference to `QStringData::deleteSelf()'
qtt.o(.text+0xa6): In function `main':
/root/Desktop/qt/qtt.cpp:10: undefined reference to `QPushButton::resize(int, int)'
qtt.o(.text+0xb2):/root/Desktop/qt/qtt.cpp:12: undefined reference to `QApplication::setMainWidget(QWidget*)'
qtt.o(.text+0xba):/root/Desktop/qt/qtt.cpp:13: undefined reference to `QWidget::show()'
qtt.o(.text+0xc2):/root/Desktop/qt/qtt.cpp:14: undefined reference to `QApplication::exec()'
qtt.o(.text+0xcc):/root/Desktop/qt/qtt.cpp:14: undefined reference to `QPushButton::~QPushButton()'
qtt.o(.text+0xd4):/root/Desktop/qt/qtt.cpp:14: undefined reference to `QApplication::~QApplication()'
qtt.o(.text+0xfa): In function `main':
/usr/lib/qt-3.3/include/qstring.h:847: undefined reference to `QString::shared_null'
qtt.o(.text+0x104):/usr/lib/qt-3.3/include/qstring.h:848: undefined reference to `QStringData::deleteSelf()'
qtt.o(.text+0x116): In function `main':
/root/Desktop/qt/qtt.cpp:14: undefined reference to `QApplication::~QApplication()'
qtt.o(.text+0x128):/root/Desktop/qt/qtt.cpp:14: undefined reference to `QPushButton::~QPushButton()'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0xc): undefined reference to `QGList::clear()'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x10): undefined reference to `QGList::~QGList()'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x14): undefined reference to `QGList::~QGList()'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x18): undefined reference to `QPtrCollection::newItem(void*)'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x20): undefined reference to `QGList::compareItems(void*, void*)'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x24): undefined reference to `QGList::read(QDataStream&, void*&)'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x28): undefined reference to `QGList::write(QDataStream&, void*) const'
qtt.o(.gnu.linkonce.r._ZTI6QGList+0x8): undefined reference to `typeinfo for QPtrCollection'
collect2: ld returned 1 exit status
make: *** [qt] 错误 1
[root@MagicLinux qt]#
[ 此贴被XChinux在2005-08-29 08:27重新编辑 ]
永 远 记 得 : 做 人 厚 道 一 点 好 。

离线running
只看该作者 1楼 发表于: 2005-08-29
你看看文档   应该QPushButton的定义不对
离线giscn
只看该作者 2楼 发表于: 2005-08-29
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 qtt.o qtt.cpp
g++ -o qt qtt.o   -L/usr/X11R6/lib -lXext -lX11 -lm

这里有问题,没有连接到 -lqt-mt,所以检查你的kdev配置,除了inlcude目录,还得注意lib目录是否配置好了
http://nzt.spaces.live.com
离线magicoy

只看该作者 3楼 发表于: 2005-08-29
楼上.你可以问Xchinux.
我做个最简单的QT程序hello world搞了半个月了............
还没搞好.............我想了各种办法都不行.你一定要帮我啊.
我QQ:290078300
我希望QQ里能说清楚点.........................谢谢了
永 远 记 得 : 做 人 厚 道 一 点 好 。

离线giscn
只看该作者 4楼 发表于: 2005-08-29
下面是引用magicoy于2005-08-29 02:22发表的:
楼上.你可以问Xchinux.
我做个最简单的QT程序hello world搞了半个月了............
还没搞好.............我想了各种办法都不行.你一定要帮我啊.
我QQ:290078300
我希望QQ里能说清楚点.........................谢谢了

晕,又不是我的问题,我问Xchinux干什么?
[ 此贴被giscn在2005-08-29 05:42重新编辑 ]
http://nzt.spaces.live.com
离线XChinux

只看该作者 5楼 发表于: 2005-08-29
汗啊。。看看那些出错信息,就一个一个的解决问题了。
在VC、TC等环境里,也给出出错信息的,那里能看,这里也能看,只不过是在控制台的。上面已经给出来出错的行号,和原因:

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 qtt.o qtt.cpp
g++ -o qt qtt.o   -L/usr/X11R6/lib -lXext -lX11 -lm
qtt.o(.text+0x33): In function `main':
/root/Desktop/qt/qtt.cpp:7: undefined reference to `QApplication::QApplication(int&, char**)'
qtt.o(.text+0x44):/root/Desktop/qt/qtt.cpp:9: undefined reference to `QString::QString(char const*)'
qtt.o(.text+0x62):/root/Desktop/qt/qtt.cpp:9: undefined reference to `QPushButton::QPushButton(QString const&, QWidget*, char const*)'
qtt.o(.text+0x77): In function `main':
/usr/lib/qt-3.3/include/qstring.h:847: undefined reference to `QString::shared_null'
qtt.o(.text+0x81):/usr/lib/qt-3.3/include/qstring.h:848: undefined reference to `QStringData::deleteSelf()'
qtt.o(.text+0xa6): In function `main':
/root/Desktop/qt/qtt.cpp:10: undefined reference to `QPushButton::resize(int, int)'
qtt.o(.text+0xb2):/root/Desktop/qt/qtt.cpp:12: undefined reference to `QApplication::setMainWidget(QWidget*)'
qtt.o(.text+0xba):/root/Desktop/qt/qtt.cpp:13: undefined reference to `QWidget::show()'
qtt.o(.text+0xc2):/root/Desktop/qt/qtt.cpp:14: undefined reference to `QApplication::exec()'
qtt.o(.text+0xcc):/root/Desktop/qt/qtt.cpp:14: undefined reference to `QPushButton::~QPushButton()'
qtt.o(.text+0xd4):/root/Desktop/qt/qtt.cpp:14: undefined reference to `QApplication::~QApplication()'
qtt.o(.text+0xfa): In function `main':
/usr/lib/qt-3.3/include/qstring.h:847: undefined reference to `QString::shared_null'
qtt.o(.text+0x104):/usr/lib/qt-3.3/include/qstring.h:848: undefined reference to `QStringData::deleteSelf()'
qtt.o(.text+0x116): In function `main':
/root/Desktop/qt/qtt.cpp:14: undefined reference to `QApplication::~QApplication()'
qtt.o(.text+0x128):/root/Desktop/qt/qtt.cpp:14: undefined reference to `QPushButton::~QPushButton()'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0xc): undefined reference to `QGList::clear()'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x10): undefined reference to `QGList::~QGList()'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x14): undefined reference to `QGList::~QGList()'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x18): undefined reference to `QPtrCollection::newItem(void*)'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x20): undefined reference to `QGList::compareItems(void*, void*)'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x24): undefined reference to `QGList::read(QDataStream&, void*&)'
qtt.o(.gnu.linkonce.r._ZTV6QGList+0x28): undefined reference to `QGList::write(QDataStream&, void*) const'
qtt.o(.gnu.linkonce.r._ZTI6QGList+0x8): undefined reference to `typeinfo for QPtrCollection'
collect2: ld returned 1 exit status
make: *** [qt] 错误 1



发现上面的错误了没有,都说的是undefined reference,还有QString, QGList,这两个根本就没有在文件里出现。你是不是在同一个目录底下还有其它的cpp文件?或者是你使用的Makefile还是以前的Makefile?把其它文件都删除了,只留源文件,然后再按步骤进行编译
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线girl2008
只看该作者 6楼 发表于: 2005-08-29
你看你编译的用的是qt-3.3的库,根本没有用你安装的QT-3.3.4的库,路径没设置.
离线yfy002

只看该作者 7楼 发表于: 2005-08-29
do you installed qt-devel?
[ 此贴被XChinux在2005-08-29 15:27重新编辑 ]
我渴望平静,风却给了我涟漪
我的blog:
http://sungaoyong.cublog.cn
离线magicoy

只看该作者 8楼 发表于: 2005-08-29
我不懂啊...........
我用的 Kdevelop
系统Magiclinux
永 远 记 得 : 做 人 厚 道 一 点 好 。

离线running
只看该作者 9楼 发表于: 2005-08-29
你这样输入看看,应该没问题了.注意要放在MAIN CPP文件中

#include <qapplication.h>
#include "helloworldForm.h"
#include <qwidget.h>
#include <qpushbutton.h>

int main( int argc, char ** argv )
{
  QApplication a( argc, argv );
 
  QWidget mainwindow;
  mainwindow.setMinimumSize(200,100);
  mainwindow.setMaximumSize(200,100);
 
  QPushButton helloworld("Hello World!",&mainwindow);
  helloworld.setGeometry(20,20,160,60);
 
  a.setMainWidget(&mainwindow);
  mainwindow.show();
  return a.exec();
}
离线magicoy

只看该作者 10楼 发表于: 2005-08-29
真的感谢楼上大哥帮助.
我在桌面建了个文件夹qt
再里面新建了main.cpp文件.把你代码贴进去.然后进终端试了..........
结果是...........
//////////////////////////////////////////////////////////////////////////////////////
[root@MagicLinux ~]# cd /root/Desktop/qt
[root@MagicLinux qt]# ls
main.cpp main.cpp~
[root@MagicLinux qt]# qmake -project
[root@MagicLinux qt]# qmake
[root@MagicLinux 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
main.cpp:2:28: helloworldForm.h: 没有那个文件或目录
make: *** [main.o] 错误 1
[root@MagicLinux qt]#

///////////////////////////////////////////////////////////////////////////////////////////
这是怎么了.要怎么办才好?我一个hello world忙了半个月了.还没搞好.谢谢大家帮助....
永 远 记 得 : 做 人 厚 道 一 点 好 。

离线XChinux

只看该作者 11楼 发表于: 2005-08-29
把#include "helloworldForm.h"
这句去掉
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线aiken
只看该作者 12楼 发表于: 2005-08-30
楼住用kdevelop的时候应该建立qmake工程 还有检查编译器option是否加入qt支持
我遇到类似的情况都是linker不知道lib的地址 在kedevelop右侧的设置加入qt的include地址和lib的地址
离线gongyh

只看该作者 13楼 发表于: 2005-09-01
我编译了你的程序,没有问题。在 4.00上只要去了a.setMainWidget( &hello );就可以了

#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();
}
打工不是一辈子的事!
离线acefunware

只看该作者 14楼 发表于: 2005-09-01
是少了头文件吧
lib的路径不对吧
代码没什么错啊
可能是你机子的环境设置的问题
email:acefunware@yahoo.com.cn
blog:http://acefunware.shineblog.com
快速回复
限100 字节
 
上一个 下一个