免费注册 查看新帖 |

Chinaunix

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

如何用gcc编译C++源程序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-03-15 08:30 |只看该作者 |倒序浏览
/*-----------hello.h--------------*/
#include <stdio.h>;

class Testmath
{
public:
float pingjun(int aa,int bb,int cc);
int a;
int b;
int c;
};


/*-----------hello.cc--------------*/

#include "hello.h"

float Testmath::pingjun(int aa,int bb,int cc)
{
a=aa;
b=bb;
c=cc;
float avg;
avg=(float)(a+b+c)/3;
return avg;
}

/*-----------main.cc--------------*/

#include "hello.h"

main()
{
float num;
Testmath testmath;
num=testmath.pingjun(23,34,56);
printf("%f\n",num);
}

假如运行#gcc -o main main.cc
出现以下:/tmp/ccGe3L6y.o(.text+0x1b): In function `main':
: undefined reference to `Testmath::pingjun(int, int, int)'
/tmp/ccGe3L6y.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

假如运行#gcc -c hello.cc
#gcc -c main.cc
#gcc -o main hello.o main.o
回出现以下:
main.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

请各位帮忙,多谢!

论坛徽章:
0
2 [报告]
发表于 2004-03-15 09:01 |只看该作者

如何用gcc编译C++源程序

把gcc改成g++
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP