tags:

views:

2238

answers:

2

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?

+13  A: 

The deal is that you're tired and dumb. :)

Use

g++ test.cpp

instead, since this is c++ code.

ryan_s
I though gcc was the front end that recognized cpp files and passed it through to the correct compiler.
paxdiablo
@Pax Diablo: Yes, it uses the correct _compiler_, however, g++ passes libstdc++ to the linker whereas gcc doesn't. :-P
Chris Jester-Young
Right, it's a linker problem, not a compilation one. I normally don't build individual files from the command line like this, so I didn't even think and just typed gcc thinking it would work.
ryan_s
I've made that same mistake myself, at least twice that I can remember. :-)
Head Geek
thanks a lot!!!
ufk
+2  A: 

the extension .cpp causes gcc to compile your file as a c++ file. According to this page the extension does matter: http://gcc.gnu.org/onlinedocs/gcc-4.4.1/gcc/Overall-Options.html#index-file-name-suffix-71 Try compiling the same file but with the .c extension (or alternatively explicitly specify the language with -x c). If you run nm test.o (where test.o is the object file resulting from running gcc -x c -c test.cpp -o test.o) you'll notice that ___gxx_personality_v0 is not listed as a symbol whereas if you run the same command on an object file generated with gcc -c test.cpp -o test.o the ___gxx_personality_v0 is present.

whitman