Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble adding Obj-C++ subproject into a Xcode Obj-C project

I created a Objective-C++ project that runs some C++ (OpenCV) code. It runs fine and everything works well. But then I decided to add these routines as a subproject to my MAIN PROJECT, I get errors whenever I try to use the subproject classes.

The thing is, my SUBPROJECT uses .mm source files whereas my MAIN PROJECT uses only .m source files: enter image description here

Every time I try to allocate a the class DyOpenCV (DyOpenCv *opencv = [DyOpenCv alloc]), I get a lot of errors: Compilation errors

Is that a tip to merge Obj-C with Obj-Cpp projects? Is that a special interface to use, once I am trying to run .mm files from .m ones? Even if the .mm files are from a subproject? Is it necessary to add all libraries of my subproject to my project (I already did that)?

Cheers,

like image 785
marcelosalloum Avatar asked Mar 24 '23 04:03

marcelosalloum


1 Answers

You need to link against the c++ standard library. This normally happens automatically if your compile sources phase contains any c++ files, but if the c++ is all contained within a static library then you need to explicitly ask for it to be linked to the final executable.

Check the subproject's build settings. Look for the C++ Standard Library build option. If it's set to libc++ (llvm standard library), then add -lc++ to your application's additional linker flags. If it's set to libstdc++ (gnu library), then add -lstdc++ to your application's additional linker flags.

like image 78
Chris Devereux Avatar answered Mar 26 '23 18:03

Chris Devereux