Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks to everyone who gave me suggestions.</p> <p>Having created my projects anew from scratch, I fiddled and logic-ed my way to the solution. Note that - at least in my case - no use of #ifdef __cplusplus was required, nor any other preprocessor directive. Only file suffix changing is essential (as detailed below).</p> <p>Here's the process:</p> <p><strong>Create C++ Static Library and Include/Link with Objective-C Library (e.g. iOS app) in XCode 4</strong>:</p> <ul> <li>In XCode 4 create a New Project of type Cocoa Touch Static Library. Hereafter we shall refer to this project as 'CProj'.</li> <li>In CProj workspace create/import as many C++ classes as required. No special suffix for filenames is necessary - all my files are .h and .cpp.</li> <li>In XCode create/open any Objective-C project e.g. iOS app. Hereafter we shall refer to this project as 'ObjProj'.</li> <li>Find CProj.xcodeproj in Finder (typically /Documents/CProj/CProj.xcodeproj), drag it onto the visible ObjProj project icon at the top of your XCode Project Navigator (visible file/folder hierarchy on left side in XCode). This now places CProj as a nested project within ObjProj.</li> <li>Left click ObjProj project icon in Project Navigator, a new pane emerges to the right, left click Build Phases in this pane.</li> <li>Under Target Dependencies click '+' icon and select CProj library icon below listed CProj project. Click OK.</li> <li>Under Link Binary With Libraries click '+' icon and select CProj library icon from within Workspace collapsible folder at top of window presented.</li> </ul> <p><strong>File Renaming Rules</strong></p> <ul> <li><p>Where including a CProj header in ObjProj, use path backtracking to identify import, e.g. #include "../../MyProj/MyImport.h" to step 2 dirs backwards then step into MyProj folder.</p></li> <li><p>Any ObjProj implementation file including a CProj header must be renamed from .m to .mm . Any ObjProj header file including a CProj header must be renamed from .h to .hh .</p></li> <li><p>Any ObjProj file including a file whose suffix is now .hh (consequence of step above) must be renamed in the same manner.</p></li> </ul> <p><em>An example: Consider you have files A.h, A.m, B.h, B.m. A.m imports B.h, and B.h includes one or more CProj headers. B.m includes type references, using CProj classes included via B.h . First renaming is B.h -> B.hh since it contains includes. Then B.m -> B.mm since it contains type references to CProj (no includes necessary since B.h has already done them). Then A.m -> A.mm since A.m which contained an include for B.h now has an include for the renamed file, B.hh .</em></p> <p>P.S. Note that the C++ library doesn't like to auto-rebuild when it should - I often have to 'Clean' then 'Build' in ObjProj after updating CProj from within it.</p>
 

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