Note that there are some explanatory texts on larger screens.

plurals
  1. POobjective-c wrapper invoking c++ static member functions
    text
    copied!<p>I am trying to make an objective-c++ wrapper (.mm) between a pure c++ class (.cpp) and pure objective-c object (.m). A good working example can be <a href="https://github.com/boralben/ObjectiveCPPWrapperEx.git" rel="nofollow">found on github</a>. I can build and run this without a problem.</p> <p>However I need to access static member functions in the c++ class. I have modified the github example by removing all existing functions and introducing a static member function: </p> <pre><code>// ================== // DummyModel.h // ================== class DummyModel { public: static int test (); }; // ================== // DummyModel.cpp // ================== #include "DummyModel.h" static int test () { int x = 1; return x; } // ================== // DummyModelWrapper.h // ================== #import &lt;Foundation/Foundation.h&gt; @interface DummyModelWrapper : NSObject - (int) test; @end // ================== // DummyModelWrapper.mm // ================== #import "DummyModelWrapper.h" #import "DummyModel.h" @implementation DummyModelWrapper - (int) test { int result; result = DummyModel::test(); return result; } @end </code></pre> <p>This yields the following error:</p> <pre><code>Undefined symbols for architecture i386: "DummyModel::test()", referenced from: -[DummyModelWrapper test] in DummyModelWrapper.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) </code></pre> <p>It is this reference to test in DummyModelWrapper.mm that is invoking the error: </p> <pre><code> result = DummyModel::test(); </code></pre> <p>The test project is adapted from the github project, which compiles and runs fine in it's unedited form (it instantiates <code>DummyModel</code> and invokes member functions on the instance). The error occurs as soon as I attempt to add a static member and access it from the wrapper object.</p> <p>I have read everything i can find on stackoverflow and elsewhere, but can only find examples involving non-static member functions. </p> <p><em>references</em><br> <a href="http://www.philjordan.eu/article/mixing-objective-c-c++-and-objective-c++" rel="nofollow">http://www.philjordan.eu/article/mixing-objective-c-c++-and-objective-c++</a><br> <a href="http://robnapier.net/blog/wrapping-cppfinal-edition-759" rel="nofollow">http://robnapier.net/blog/wrapping-cppfinal-edition-759</a><br> <a href="http://www.boralapps.com/an-objective-c-project-that-uses-c/294/" rel="nofollow">http://www.boralapps.com/an-objective-c-project-that-uses-c/294/</a> </p> <p><em>environment</em><br> xcode 4.5.2/osx8.2 (targeting ios5+)</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