In my static lib project(target:sdk.a), I used an extern function like this:
// in the PlatformUnity.h file
extern "C"{
extern UIView * UnityGetGLView();
extern UIViewController * UnityGetGLViewController();
}
// in the PlatformUnity.mm file (*.mm NOT the *.m)
UIView * funcA(){
return UnityGetGLView();
}
UIViewController * funcB(){
return UnityGetGLViewController();
}
In another project named Unity-iPhone.xcodeproj, I used the SDK.a .
And there’s a file named AppController.mm contains the code below:
static UIViewController* sGLViewController = nil;
UIViewController* UnityGetGLViewController()
{
return sGLViewController;
}
static UIView* sGLView = nil;
UIView* UnityGetGLView()
{
return sGLView;
}
When I build the Unity-iPhone.xcodeproj, It tells me that it can’t find the function UnityGetGLView(). link error below:
Undefined symbols for architecture armv7:
"_UnityGetGLViewController", referenced from:_funcB in SDK.a(PlatformUnity.o)
"_UnityGetGLView", referenced from:_funcA in SDK.a(PlatformUnity.o)
This two function are really defined in AppController.mm But why I can’t find it when link? The other linker flag of Unity-iPhone.xcodeproj is below:
-all_load -weak_framework CoreMotion -weak-lSystem
I was able to solve this problem. The reason was I hadn’t added extern “C” to “UnityGetGLViewController” method. Compiler was compiling it as C++ function but actually it has to be compiled as C function.
i.e. Use following Code snippets