如何用gcc编译C++源程序
/*-----------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
请各位帮忙,多谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
把gcc改成g++