日期:2014-05-16  浏览次数:20661 次

gcc链接的时候报错,为什么?
我写了一个很简单的程序。gcc编译不过,但是g++可以

[m@myLinuxLocalhost ~]$ cat hw.cpp
#include<stdio.h>
int main(void){
  printf("hw\n");
  return 0;
}
[m@myLinuxLocalhost ~]$ gcc hw.cpp
/tmp/ccjUzKu5.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld 返回 1
[m@myLinuxLocalhost ~]$ gcc hw.cpp -lc
/tmp/ccSA8rsZ.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld 返回 1
[m@myLinuxLocalhost ~]$ g++ hw.cpp
[m@myLinuxLocalhost ~]$ 

是不是gcc还缺少什么链接的参数? 我已经加上了 -lc啊

------解决方案--------------------
程序只在一个.c里写的?我看undefined reference一般都是多个文件互相调用函数,但有的函数原型没写。
------解决方案--------------------
cpp是用g++来编译的,不是gcc
------解决方案--------------------
gcc hw.cpp -lstdc++