Note that there are some explanatory texts on larger screens.

plurals
  1. POXcode: Referencing C++ project from Objective-C project
    primarykey
    data
    text
    <p>I'm beginning to tear my hair out over this, so it's time to post here!</p> <p>I have a C++ project in XCode, built as a Command Line Tool. All .cpp files have been renamed as .mm, there is one .hh and a few .h headers. I've specified 'Compile Sources As -> Objective-C++' in Build Settings.</p> <p>I have another XCode project for an iOS app. This is set to 'Compile Sources As -> According to File Type'. I can't set it to compile everything as Objective-C++ since some parts of the project won't compile as Obj-C++.</p> <p>There is one class in the iOS app where I wish to utilise my C++ project, and it consists of files MyClass.hh, MyClass.mm; they were simply .h and .m but I renamed them in the hope of remedying this problem.</p> <p>I dragged my cpp project into the iOS project. I then added a Target Dependency in the iOS Build Phases to point to the cpp CLI application.</p> <p>In MyClass.hh I have</p> <pre><code>#include "../path/to/CppProject/ImportAll.h" </code></pre> <p>..which is a header file that successively 'include's all headers from the cpp project. I then go about my business, creating one property within MyClass.hh which is a pointer to a cpp object, and various references within MyClass.mm to cpp classes.</p> <p>The darn thing just won't compile though - I get a ton of messages relating to my cpp classes like this:</p> <pre><code>MyCPPFile.h:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&lt;' token </code></pre> <p>Is the compiler not recognising that MyClass.hh is Objective-C++ not Objective-C? Should I have a target dependency which is a library instead of pointing to this CLI app, perhaps?</p> <p>I've googled around for a while trying to solve the problem. I've seen references to people using</p> <pre><code>#ifdef __cplusplus </code></pre> <p>or else having to rename files to .mm to get things working, but in other cases people simply say they drag and drop projects across with no issues.</p> <p>Can someone please enlighten me, and explain what key steps I should be performing to make this work? I'd be very grateful! Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload