LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: basten54188

gcc问题!

[复制链接]
发表于 2003-5-18 20:11:40 | 显示全部楼层
如果只是声明一个函数
但没有定义它
那么就会报unresolve error ,xxx not found

就是这个原因
 楼主| 发表于 2003-5-18 20:17:12 | 显示全部楼层
你看我的form1.h的源代码!有FORM1的定义啊!
form1.h
#ifndef FORM1_H
#define FORM1_H

#include <qvariant.h>
#include <qwidget.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QPushButton;

class Form1 : public QWidget
{
Q_OBJECT

public:
Form1( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~Form1();

QPushButton* PushButton1;


};

#endif
发表于 2003-5-18 20:17:20 | 显示全部楼层
既然gcc -I/usr/lib/qt/include main.cpp -L/usr/lib/qt/lib -lqt没多少错误,那你试试:
g++ -I/usr/lib/qt/include main.cpp form1.cpp -L/usr/lib/qt/lib -lqt
发表于 2003-5-18 20:23:23 | 显示全部楼层
libinary兄回答问题很是细心呀,值得表扬。
 楼主| 发表于 2003-5-18 20:30:36 | 显示全部楼层
KJ501兄别光表扬别人啊!
你也帮偶瞧瞧程序!
发表于 2003-5-18 20:40:06 | 显示全部楼层
我不懂QT,帮不上忙。
发表于 2003-5-18 20:44:25 | 显示全部楼层
头文件只是声明
而不是定义


{
}这个的才叫定义
发表于 2003-5-18 20:46:10 | 显示全部楼层
另外-c表示只是编译不连接
如果一个程序由多个c文件组成
那么对每个c文件选编译
最后再连接它们生成的.o文件
精华那篇文章看了没有
看看gcc选项说明
另外也建议看看其它人写的makefile
发表于 2003-5-18 20:47:13 | 显示全部楼层
如程序a 由 a.cpp b.cpp组成
那么
gcc -c a.cpp -o a.o
gcc -c b.cpp -o b.o
gcc a.o b.o -o a//产生a程序
 楼主| 发表于 2003-5-18 21:07:36 | 显示全部楼层
libinary 老兄:按照你说的那样的话错误更多!
/tmp/ccV6jusA.o: In function `Form1::Form1[not-in-charge](QWidget*, char const*, unsigned)':
/tmp/ccV6jusA.o(.text+0x20): undefined reference to `vtable for Form1'
/tmp/ccV6jusA.o(.text+0x2c): undefined reference to `vtable for Form1'
/tmp/ccV6jusA.o(.text+0x73): undefined reference to `Form1::trUtf8(char const*, char const*)'
/tmp/ccV6jusA.o(.text+0x18f): undefined reference to `Form1::trUtf8(char const*, char const*)'
/tmp/ccV6jusA.o: In function `Form1::Form1[in-charge](QWidget*, char const*, unsigned)':
/tmp/ccV6jusA.o(.text+0x23c): undefined reference to `vtable for Form1'
/tmp/ccV6jusA.o(.text+0x248): undefined reference to `vtable for Form1'
/tmp/ccV6jusA.o(.text+0x28f): undefined reference to `Form1::trUtf8(char const*, char const*)'
/tmp/ccV6jusA.o(.text+0x3ab): undefined reference to `Form1::trUtf8(char const*, char const*)'
/tmp/ccV6jusA.o: In function `Form1::~Form1 [not-in-charge]()':
/tmp/ccV6jusA.o(.text+0x443): undefined reference to `vtable for Form1'
/tmp/ccV6jusA.o(.text+0x44f): undefined reference to `vtable for Form1'
/tmp/ccV6jusA.o: In function `Form1::~Form1 [in-charge]()':
/tmp/ccV6jusA.o(.text+0x489): undefined reference to `vtable for Form1'
/tmp/ccV6jusA.o(.text+0x495): undefined reference to `vtable for Form1'
/tmp/ccV6jusA.o: In function `Form1::~Form1 [in-charge deleting]()':
/tmp/ccV6jusA.o(.text+0x4cf): undefined reference to `vtable for Form1'
/tmp/ccV6jusA.o(.text+0x4db): more undefined references to `vtable for Form1' follow
collect2: ld returned 1 exit status
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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