Monday, December 3, 2007

undefined reference to `__gxx_personality_v0' !!!!


Stunned by this error message when i tried to compile a simple c++ test program under UNIX.
> gcc -o out atol.cpp
/tmp/cci91B6Q.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

actually i spend a half an hour to rectify this, but later only i found it as a programmers blooper ( shame on me ! )

Even if the gcc and g++ are from the GNU's compiler collection, there is a significant difference between them, at least for the context for using them.

The mistake was i tried to compile and link the a .cpp file by using the 'gcc' compiler. but the programs using the c++ object files should always be linked with g++ in order to supply the c++ libraries. My mistake was i tried to link the c++ object files to be linked with c libraries, and thus it showed 'Undefined reference'.

These undefined reference to the internal library functions like - __gxx_personality_v0.
when you see such an error, it is because you tried to link the C++ object files with gcc.

But there is another question, why the gcc worked in the first place?
It is like that - actually gcc will compile the c++ file, when it found a .cpp extension. but it cannot successfully link the generated object file(s)

These are very small things, but its enough to take away a good chunk of our time.

1 comment:

Anonymous said...

thanks . i got the same error . but instead of rectifying , i googled it. +1