When XCode 4 Cocoa Development Meets a C++ Library

I've been developing an Xcode 4 Cocoa application and a C++ Gaming SDK library in tandem.   The SDK uses CMake and builds outside of XCode on the terminal, generating a static library binary.  The SDK, while developed in C++ exposes a C API.  The app links to this library using the C API.

Some of my overly technical requirements are:

  • Avoiding the need for Objective-C++ source files in the application project (whether avoiding ObjC++ is a worthwhile goal is besides the point.)
  • Internally the SDK can use the standard C++11 library (or other C++11 libraries as the need arises.)
  • No RTTI or std exception handling.

For example the SDK internally uses C++11 smart pointers. But the public C API used by the Cocoa app abstracts all of this. Though when it comes time to build my simple Cocoa application, I get the following link errors:

    Undefined symbols for architecture x86_64: "std::__1::__shared_weak_count::__get_deleter(std::type_info const&) const", referenced from: vtable for std::__1::__shared_ptr_emplace > in libckoverview.a(stage.cpp.o) "std::__1::__shared_weak_count::__add_shared()", referenced from: cinekine::overview::Stage::getMapPtr() in libckoverview.a(stageapi.cpp.o) "std::__1::__shared_weak_count::__release_shared()", referenced from: std::__1::shared_ptr::~shared_ptr() in libckoverview.a(stageapi.cpp.o) std::__1::shared_ptr::~shared_ptr() in libckoverview.a(stage.cpp.o) "std::__1::__shared_weak_count::~__shared_weak_count()", referenced from: std::__1::__shared_ptr_emplace >::~__shared_ptr_emplace() in libckoverview.a(stage.cpp.o) 

And so on...

Verified my Xcode project has exceptions and RTTI turned off. Also verified the c++11 and libc++ flags, etc. Also tried building my library with RTTI and exception handling turned on, but had no luck.

After pounding my head for a couple hours, I decided to add a simple stub CPP file to my Cocoa project. Links beautifully.

Looks like Xcode has no idea you care about C++ (i.e.linking to the standard library) unless you have C++ source in your project. Makes total sense once you think about it.