私の静的ライブラリ プロジェクト (target:sdk.a) では、次のような extern 関数を使用しました。
// 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();
}
Unity-iPhone.xcodeproj という別のプロジェクトでは、SDK.a を使用しました。AppController.mm という名前のファイルには、以下のコードが含まれています。
static UIViewController* sGLViewController = nil;
UIViewController* UnityGetGLViewController()
{
return sGLViewController;
}
static UIView* sGLView = nil;
UIView* UnityGetGLView()
{
return sGLView;
}
Unity-iPhone.xcodeproj をビルドすると、関数 UnityGetGLView() が見つからないことがわかります。以下のリンク エラー:
Undefined symbols for architecture armv7:
"_UnityGetGLViewController", referenced from:_funcB in SDK.a(PlatformUnity.o)
"_UnityGetGLView", referenced from:_funcA in SDK.a(PlatformUnity.o)
この 2 つの関数は実際には AppController.mm で定義されています。Unity-iPhone.xcodeproj の他のリンカー フラグは次のとおりです。
-all_load -weak_framework CoreMotion -weak-lSystem