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

发布于 2022-10-01 21:03:32 字数 1303 浏览 13 评论 0

/*-----------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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨与橙与城 2022-10-08 21:03:32

把gcc改成g++

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文