Search code examples
c++iphoneobjective-cios-simulatorobjective-c++

Objective-C++ compiles for iPhone, but not simulator


I have a C++ library I want to add to my iphone project.

In one header file I declare

@interface a
{
   cppvirtualclass V;
}

This compiles fine for the iPhone device with Release settings. However it refuses to compile for the Simulator with or without debug info.

It give the error

error: type 'V' has virtual member functions.

Is there a way out of this or do I have to define only concrete C++ classes?


Solution

  • By default Objective C does not run constructors on C++ instance variables when it creates Objective C objects. This means (I think) that the C++ object's vtable will not get initialised correctly.

    Try making your instance variable a pointer and allocating it in the init method (and destroying it in dealloc/finalize).

    Or

    try setting "Call C++ default Ctors/Dtors in Ovjective-C" in your target code generation settings.

    (GCC_OBJC_CALL_CXX_CDTORS, -fobjc-call-cxx-cdtors)