Undefined Symbol ___gxx_personality_v0 by reference

I got this undefined character build using this command line:

$ gcc test.cpp Undefined symbols: "___gxx_personality_v0", referenced from: etc... 

test.cpp is simple and should work just fine. What a deal?

+46
c ++ c gcc g ++
Oct 15 '08 at 2:36
source share
4 answers

Using

 g++ test.cpp 

instead, since this is C ++ code.




Or, if you really want to use gcc , add -lstdc++ to the command line, for example:

 gcc test.cpp -lstdc++ 

Executing md5 with respect to a.out generated for each scenario shows that it has the same result.

But, yes, g++ probably makes your world a simpler place.

+75
Oct 15 '08 at 2:38
source share

The .cpp extension calls gcc to compile your file as a C ++ file. (See GCC Docs .)

Try compiling the same file, but rename it with the extension .c :

 mv test.cpp gcc test.c 

Alternatively, you can explicitly specify the language by passing -xc compiler:

 gcc -xc -c test.cpp -o test.o 



If you run nm test.o in these C versions, you will notice that ___gxx_personality_v0 not specified as a character.
(And if you execute the same command in the object file generated with gcc -c test.cpp -o test.o , the ___gxx_personality_v0 character is ___gxx_personality_v0 .)

+4
Oct 26 '09 at 17:13
source share

Just in case, I have the same problem as me: the file extension must be .c not a .c (gcc is case sensitive).

+3
Dec 02 '10 at
source share

Had the same problem but a different solution:

C ++ - code in a static library, linked and referencing a .m file. Renaming the .m file to .mm fixed the problem.

+1
Aug 29 '13 at 18:38
source share



All Articles