undefined reference to `__gxx_personality_v0' with gcc [duplicate]

假如想象 提交于 2019-12-01 09:47:19

问题


Possible Duplicate:
What is __gxx_personality_v0 for?

I've seen this question circulating around here in the context of compiling C++ code. However I am to compile a pure C code and keep on getting this error. I am forbidden to use "-lstdc++" as a workaround to this gcc problem. How to change my code to get it working and why is this error popping out?

My simplified code:

//this is main.cpp
#include <stdio.h>
int main()
{
    char ch[3];
    ch[0] = getc(stdin);
    ch[1] = getc(stdin);
    ch[2] = '\0';
    printf("%s\n", ch);
    return 0;
}

My compile command is:

gcc main.cpp

回答1:


Use either g++ - since your file is suffixed .cpp or rename the file to .c and keep the command line as is. Tested on Debian 6.0.5 with gcc 4.4.5.




回答2:


man gcc says:

C++ source files conventionally use one of the suffixes .C, .cc, .cpp, .CPP, .c++, .cp, or .cxx; C++ header files often use .hh, .hpp, .H, or (for shared template code) .tcc; and preprocessed C++ files use the suffix .ii. GCC recognizes files with these names and compiles them as C++ programs even if you call the compiler the same way as for compiling C programs (usually with the name gcc).



来源:https://stackoverflow.com/questions/10801542/undefined-reference-to-gxx-personality-v0-with-gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!