views:

24

answers:

1

I have an Objective-C/Cocoa project that incorporates a static library. That static library has some object files that have C++ in them.

I've found that if the project that I'm using the library in contains no other C++ in it, the link fails (can't link new/delete/etc). But simply adding a single (empty) .cpp file to the project causes the link to succeed.

In practice, what happens is that the build will invoke g++ instead of gcc when there is any cpp, which succeeds. No other difference in the build is apparent to me.

Is there an explicit switch I can use to link in this library without using the dummy cpp file in the project?

(This is mostly a curiosity question-- it's not the end of the world to put in one empty file. :) )

Thanks.

+2  A: 

try to link libstdc++

gcc main.c -lstdc++

or in Xcode: Project->Edit Project Settings

To the config section "Other Linker Flags", add -lstdc++.

loentar
Bingo, thanks. Edited your answer to show others how to accomplish this in Xcode.
quixoto