Undefined Symbol ___gxx_personality_v0 on link
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.
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.cppgcc 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.)