I am trying to make a wrapper in Objective-C so I don’t have to write c++ outside the library classes.
The Library main file is LLAHProcessor.h .cpp
My Wrapper is LLAHProcessorWrapper.h .mm
It compiles fine, but when I add LLAHProcessorWrapper to other class, (Lets say an UIView) as a member variable I get hundreds of errors, like:
#include <map> : Map no such a file or directory
and in every c++ class/struct:
Expected specifier-qualifier list before ClassName
Is like compiler is not recognizing c++ code.
I wonder what am I missing here.
Does it has to be something with the fact I added this to Xcode Target Properties: ?
Other Link Flags : -lstdc++ -lz
Or maybe I need to add new flags here?
Thanks in advance
Your problem is that
.mfiles are compiled as C instead of C++. Thus when the compiler comes across any C++ even in a header file while compiling a.mfile, it will barf.No doubt you have to put some C++ in your header file because your Objective C object wraps a C++ object, but there are ways around this. One way would be to use a pointer to the C++ object and make use of the handy preprocessor define
__cpluspluswhich is defined for C++ (and Objective-C++) but not for C (or Objective-C) e.g.Since you never dereference the members of the cppObject outside of the
.mmfile it doesn’t matter that you never provide a full definition for the struct.You would
newanddeletethe pointer in-initand-deallocrespectively. You would include the full C++ class declaration inLLAHProcessorWrapper.mm.