views:

205

answers:

1

So I'm still feeling like a novice at times when strange errors jump out of XCode. Yesterday I started getting this:

___gxx_personality_v0", referenced from: ___gxx_personality_v0$non_lazy_ptr

That was when building a unit test target that used a ".mm" file in XCode with the iPhoneSDK. The error went away when I changed the file extension back to ".m" since I was not yet using C++ code in it. (Though I plan to.) With my limited knowledge I googled and saw others indicating the wrong compiler was being used. Another link referred to a flag being incorrectly set. With even more limited knowledge I decided the linker options in the UnitTest target was the place to go. As it turns out the "Standard C++ Library type setting is set to Dynamic by default. Changing this setting to static made my error go away and my test now green bars... err... green buttons. I'm asking here because I still don't know exatcly what I'm doing. Obviously this setting affects the compiler but I need more detail. Am I setting myself up for another catastrophy down the road. What negative impact will this have if any? Why have I not hit the problem before? I've used ".mm" files in unit tests before though I believe I was then using the GoogleToolsForMac code base to do unit testing where I now use native XCode support for unit testing. Can somebody explain for me?

+3  A: 

Short answer: The error happens because you compile C++ code with the gcc driver instead of g++.

Longer answer: When you do call gcc myfile.mm, the GCC driver is smart enough to recognize from the .mm file extension that you're compiling Objective-C++ code, and so it compiles it well. But then, at link time, if you still use gcc as a driver (maybe you compile and link in one step?), it doesn't automatically link in the C++ stanbard library (and support object files), thus failing to link.

FX
I kinda undeerstand, but how does that apply to XCode? I'm not setting any driver, gcc or g++. I just click the build button. (call me ignorant.) Is there a build setting in XCode to tell it when to use what driver?
Cliff
It should understand from a. the file extension (`.mm`) and b. the type of file you created (File > New > C++ class, or something like that).
FX