undefined reference to `__gxx_personality_v0'

来源:互联网 发布:涉税软件下载 编辑:程序博客网 时间:2024/05/22 07:53

undefined reference to `__gxx_personality_v0'


刚刚在做一个实验,编译的时候出了一点问题,下面附上代码:

#include <stdio.h>#include <stdlib.h>#include <unistd.h>static void my_exit1(void);static void my_exit2(void);intmain(void){if (atexit(my_exit2) != 0)printf("can not register my_exit2\n");if (atexit(my_exit1) != 0)printf("can not register my_exit1\n");if (atexit(my_exit1) != 0)printf("can not register my_exit1'=\n");printf("main is done\n");return(0);}static voidmy_exit1(void){printf("first exit handler\n");}static voidmy_exit2(void){printf("second exit handler\n");}

检查了很多遍发现没啥问题呀,但是用以下编译语句时报错:

gcc -o main main.C

报错信息如下:

/tmp/ccAi9DGt.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld 返回 1

后来查找资料后得知,这里我用的是gcc来编译的,源文件却是.C(实际内容是c),实际.C代表着是c++的源文件,额,就报错了。

解决办法(改成c文件后缀即可):

mv main.C main.c
gcc -o main main.c

编译通过。

网上还有别的类似的编译错误,这里留个mark,以后发现类似的再来这里总结下~
0 0