免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 8526 | 回复: 4
打印 上一主题 下一主题

Qt 编译 undefined reference 出错 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-02-12 12:01 |只看该作者 |倒序浏览
菜鸟刚接触QT, 按<<c++ GUI programming with Qt3>>写了个hello Qt!
如下:

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

int main(int argc, char *argv[])
{
        QApplication app (argc, argv);
        QLabel *label = new QLabel("Hello Qt!", 0);
        app.setMainWidget(label);
        label->show();
        return app.exec();
}


在make 时出现很多 undefined reference 报错, 请帮忙!!!!


[root@ws qt]# make
g++ -c -pipe -Wall -W -O2 -g -march=i386 -mcpu=i686 -DQT_NO_DEBUG  -I/usr/lib/qt-3.3/mkspecs/default -I. -I. -I/usr/lib/qt-3.3/include -o hello.o hello.cpp
g++  -o qt hello.o    -L/usr/X11R6/lib -lXext -lX11 -lm
hello.o(.text+0x32): In function `main':
/root/qt/hello.cpp:6: undefined reference to `QApplication:Application(int&, char**)'
hello.o(.text+0x41):/root/qt/hello.cpp:7: undefined reference to `QString:String(char const*)'
hello.o(.text+0x6d):/root/qt/hello.cpp:7: undefined reference to `QLabel:Label(QString const&, QWidget*, char const*, unsigned int)'
hello.o(.text+0x7f): In function `main':
/usr/lib/qt-3.3/include/qstring.h:847: undefined reference to `QString::shared_null'
hello.o(.text+0x89):/usr/lib/qt-3.3/include/qstring.h:848: undefined reference to `QStringData::deleteSelf()'
hello.o(.text+0x95): In function `main':
/root/qt/hello.cpp:8: undefined reference to `QApplication::setMainWidget(QWidget*)'
hello.o(.text+0xa:/root/qt/hello.cpp:10: undefined reference to `QApplication::exec()'
hello.o(.text+0xb2):/root/qt/hello.cpp:10: undefined reference to `QApplication::~QApplication()'
hello.o(.text+0xe4):/root/qt/hello.cpp:10: undefined reference to `QApplication::~QApplication()'
hello.o(.text+0x10c): In function `main':
/usr/lib/qt-3.3/include/qstring.h:847: undefined reference to `QString::shared_null'
hello.o(.text+0x116):/usr/lib/qt-3.3/include/qstring.h:848: undefined reference to `QStringData::deleteSelf()'
hello.o(.gnu.linkonce.r._ZTV6QGList+0xc): undefined reference to `QGList::clear()'
hello.o(.gnu.linkonce.r._ZTV6QGList+0x10): undefined reference to `QGList::~QGList()'
hello.o(.gnu.linkonce.r._ZTV6QGList+0x14): undefined reference to `QGList::~QGList()'
hello.o(.gnu.linkonce.r._ZTV6QGList+0x1: undefined reference to `QPtrCollection::newItem(void*)'
hello.o(.gnu.linkonce.r._ZTV6QGList+0x20): undefined reference to `QGList::compareItems(void*, void*)'
hello.o(.gnu.linkonce.r._ZTV6QGList+0x24): undefined reference to `QGList::read(QDataStream&, void*&'
hello.o(.gnu.linkonce.r._ZTV6QGList+0x2: undefined reference to `QGList::write(QDataStream&, void*) const'
hello.o(.gnu.linkonce.r._ZTI6QGList+0x: undefined reference to `typeinfo for QPtrCollection'
collect2: ld returned 1 exit status
make: *** [qt] Error 1

论坛徽章:
0
2 [报告]
发表于 2007-02-12 13:41 |只看该作者
“undefined reference”错误一般是在连接的时候没有找到需要的库而产生的错误。你上面的程序就是由于连接时没有指定相应的 Qt 库从而造成了连接错误。这说明你的 Makefile 建立得不正确。说说你是怎么做的。

论坛徽章:
0
3 [报告]
发表于 2007-02-12 14:38 |只看该作者

回复 2楼 whyglinux 的帖子

我按<<c++ GUI programming with Qt3>>里说的方法, 运行 qmake -project 和 qmake qt.pro, 之后运行make 就报错了.

操作如下:

[root@ws qt]# ll
總計 4
-rw-r--r--  1 root root 224  2月  9 19:20 hello.cpp
[root@ws qt]# qmake -project
[root@ws qt]# ll
總計 8
-rw-r--r--  1 root root 224  2月  9 19:20 hello.cpp
-rw-r--r--  1 root root 287  2月 12 17:35 qt.pro
[root@ws qt]# qmake qt.pro
[root@ws qt]# ll
總計 12
-rw-r--r--  1 root root  224  2月  9 19:20 hello.cpp
-rw-r--r--  1 root root 2565  2月 12 17:35 Makefile
-rw-r--r--  1 root root  287  2月 12 17:35 qt.pro

然后就运行 make 就会有上面的错误.

谢谢!

论坛徽章:
0
4 [报告]
发表于 2007-02-12 15:44 |只看该作者
问题已经查明:Qt 程序项目不能以 "qt"、“qt-mt”、“qte” 等作为其顶级目录名。把目录名换为其它名字应该就可以了。

论坛徽章:
0
5 [报告]
发表于 2007-02-12 15:58 |只看该作者

回复 4楼 whyglinux 的帖子

成功了!  非常感谢!!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP