I have written a simple C program using gcc compiler in Ubuntu enviroment. The code is simple. Howver, when i try to compile, it is giving an error which I am not able to fathom. Here is the code and the error
# include <stdio.h>
int main() {
enum mar_status {
single,married,divorced
};
enum mar_status person1,person2;
person1 = single;
printf("%d\n",person1); //line B
}
I am getting the follow开发者_如何学Pythoning error when I compile
gcc enum2.cc
/tmp/cc6stgaW.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status
If I remove the printf statement at line B, everything goes fine. Any ideas as to why the compilation is failing ?
You are using gcc to compile C++ code? (.cc
extension)
Either rename the file to enum2.c
or compile with g++
.
Undefined references to internal run-time library functions, such as __gxx_personality_v0, are also a symptom of linking C++ object files with gcc instead of g++.
Changing file extension from .cc or .cpp to .c will resolve the issue.
You are confusing the compiler - when you say:
gcc enum2.cc
it thinks you are compiling C++ code, but you are doing it with gcc, which doesn't link the correct C++ libraries. Use:
gcc enum2.c
Its running fine. Check : http://ideone.com/bhjlf
I guess your command to compile is wrong.
精彩评论