c++ undefined reference - What is __gxx_personality_v0 for?
It's part of the exception handling. The gcc EH mechanism allows to mix various EH models, and a personality routine is invoked to determine if an exception match, what finalization to invoke, etc. This specific personality routine is for C++ exception handling (as opposed to, say, gcj/Java exception handling).
This is a second-hand question from an OS development site, but it made me curious since I couldn't find a decent explanation anywhere.
When compiling and linking a free-standing C++ program using gcc, sometimes a linker error like this occurs:
out/kernel.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
This is apparently because this symbol is defined in libstdc++, which is missing in a free-standing environment. Fixing the problem simply requires defining this symbol somewhere:
Which is nice, but I don't like things that just magically work... So the question is, what is the purpose of this symbol?
I had this error once and I found out the origin:
I was using a gcc compiler and my file was called
CLIENT.C despite I was doing a C program and not a C++ program.
gcc recognizes the
.C extension as C++ program and
.c extension as C program (be careful to the small c and big C).
So I renamed my file
CLIENT.c program and it worked.
The answers above are correct: it is used in exception handling. The manual for GCC version 6 has more information (which is no longer present in the version 7 manual). The error can arise when linking an external function that - unknown to GCC - throws Java exceptions.