Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined Symbol ___gxx_personality_v0 on link

Tags:

c++

c

gcc

g++

I've been getting this undefined symbol building with this command line:

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

test.cpp is simple and should build fine. What is the deal?

like image 523
ryan_s Avatar asked Oct 15 '08 02:10

ryan_s


4 Answers

Use

g++ test.cpp

instead, since this is c++ code.


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

gcc test.cpp -lstdc++

Running md5 against the a.out produced under each scenario shows that it's the same output.

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

like image 65
3 revs, 2 users 67% Avatar answered Nov 17 '22 01:11

3 revs, 2 users 67%


The .cpp extension causes gcc to compile your file as a C++ file. (See the GCC docs.)

Try compiling the same file, but rename it to have a .c extension:

mv test.cpp
gcc test.c

Alternatively, you can explicitly specify the language by passing -x c to the compiler:

gcc -x c -c test.cpp -o test.o

If you run nm test.o on these C-language versions, you'll notice that ___gxx_personality_v0 is not listed as a symbol.
(And if you run the same command on an object file generated with gcc -c test.cpp -o test.o, the ___gxx_personality_v0 symbol is present.)

like image 24
pseudosudo Avatar answered Nov 17 '22 00:11

pseudosudo


Just in case anyone has the same problem as me: The file extension should be a .c not a .C (gcc is case-sensitive).

like image 3
inket Avatar answered Nov 17 '22 01:11

inket


Had the same problem, but a different solution:

C++ code in static library getting linked, and being referenced by a .m file. Renaming the .m file to .mm fixed the issue.

like image 2
BadPirate Avatar answered Nov 17 '22 00:11

BadPirate