Objective-c shell calling C ++ static member functions

I am trying to create an objective-c ++ wrapper (.mm) between a pure C ++ class (.cpp) and a pure objective-c object (.m). A good working example can be found on github . I can create and run this without a problem.

However, I need to access the static member functions in the C ++ class. I modified the github example by removing all existing functions and introducing a static member function:

// ================== // DummyModel.h // ================== class DummyModel { public: static int test (); }; // ================== // DummyModel.cpp // ================== #include "DummyModel.h" static int test () { int x = 1; return x; } // ================== // DummyModelWrapper.h // ================== #import <Foundation/Foundation.h> @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 

This results in the following error:

 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) 

This is this validation link in DummyModelWrapper.mm, which is causing the error:

  result = DummyModel::test(); 

The testing project is adapted from the github project, which compiles and runs in it in unedited form (it creates an instance of DummyModel and calls member functions in the instance). The error occurs as soon as I try to add a static member and access it from the wrapper object.

I read everything that I can find on stackoverflow and elsewhere, but I can only find examples involving non-static member functions.

links
http://www.philjordan.eu/article/mixing-objective-c-c++-and-objective-c++
http://robnapier.net/blog/wrapping-cppfinal-edition-759
http://www.boralapps.com/an-objective-c-project-that-uses-c/294/

Wednesday
xcode 4.5.2 / osx8.2 (focus on ios5 +)

0
c ++ objective-c xcode
Dec 31 '13 at 17:40
source share
1 answer

Inside DummyModel.cpp replace

 static int test () { ... } 

Across

 int DummyModel::test () { ... } 
+2
Dec 31 '13 at 17:47
source share



All Articles