GCC compiler error while compiling *.c file
Dear Friends,
I write a program in C i.e. Hello.C When I try to compile it by giving the following command $ cc Hello.C oR $ gcc Hello.C I always got this error cc HELLO.C /tmp/ccB6cpfR.o: (.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status Please help me to get out of it. Thanks |
I guess the compiler thinks your source is C++,
try the same thing with lowercase filename: hello.c |
Quote:
ssvirdi, if you have some reason to want to keep the name Hello.C instead of changing it to Hello.c you could compile it with gcc -xc Hello.C The -xc option tells gcc the type of the input file is "c". If it knows the type already, it doesn't decide the type based on the extension (the .C). The confusing error message you got is because the gcc command invokes the linker for a .c program regardless of the type of the input file. So your .C file is compiled as a C++ module but linked as a .c program, resulting in that link time error. That behavior must seem silly when operating on just one input file. But gcc can compile and link multiple files in one command including mixed language programs. So this behavior that seems silly with one input file makes sense for more complicated commands. |
The "case" doesn't make any difference on gcc version 4.5.0 .
I just tried that with a file h.C, there weren't any problems shown. |
But with gcc-4.3.2 it can be reproduced easily:
Code:
|
so, the crux is to shift to the newer gcc version. ;)
|
Another option (if you are not root-user, for example) is following the standard: the extension is .c for C-language, not .C
|
Quote:
The proper solution is to use a lowercase ".c" extension. Uppercase ".C" means C++, so don't use it for C source code. |
Quote:
|
(If you aren't superuser, then you are not supposed to install new versions of gcc, but you can still follow the naming standards and use the extension .c for C-language.)
|
Quote:
I am routinely compiling from source not as 'root' user more than 370 targets and install them in a non-system directory of mt liking. Even though it's my personal machine and I have root access. But what does it have to do with a wrong file extension in the first place ? |
Quote:
|
(I don't think we should continue this argumentation, because basically we all suggest the same thing: using the correct file-extension.)
|
All times are GMT -5. The time now is 07:14 AM. |