tags:

views:

188

answers:

2
#include<stdio.h>
#include<ctype.h>

int main()
{
    char a,b;
    FILE *fp;
    fp=fopen("lext.txt","w");


    fprintf(fp,"PLUS");

return 0;
}

the error i get is this

/tmp/ccQyyhxo.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
+14  A: 

You are compiling a .cpp file with gcc. Rename the file to end with .c so it compiles as C code or compile it with the C++ driver g++. That will link in the stdc++ library providing these functions.

Johannes Schaub - litb
Works both ways round for me. Not saying you're wrong, but Which bit of the c++ library do you think is necessary for this code sample?
anon
@Neil it's implicitly referencing those exception support functions. Personality routines are defined by the Itanium C++ ABI. See http://www.codesourcery.com/public/cxx-abi/abi-eh.html#base-personality
Johannes Schaub - litb
obviously `__gxx_personality_v0`;-)
swegi
anon
@Neil if you pass `-fno-exceptions`, it compiles/links fine. I don't know how GCC's exceptions work on Windows, but apparently in a way that makes this "work". However, that's hardly a proper way. If you really want to compile that file with `GCC`, you should pass `-x c` to indicate it's a C file.
Johannes Schaub - litb
@Johannes Couldn't (and shouldn't) the linker strip out those references, since they are evidently not called - this being pure C code?
anon
@Neil you can't know whether an `extern "C"` function you call doesn't throw (it could be defined by a C++ library, after all). If it throws, your C++ code has to do unwinding, thus it's referencing those functions even though in your code you don't directly call the function it references.
Johannes Schaub - litb
+2  A: 

ld is the linker and it is reporting that there is a link problem. The gxx part of the error message hints that it has something to do with a C++ problem which makes the answer Johannes Schaub - litb gives about the root cause correct.

epatel
@Neil Butterworth I thought it could be good to point out how to interpret the error message and what might have led Johannes to come up with the solution.
epatel