1

私の静的ライブラリ プロジェクト (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
4

1 に答える 1

3

この問題を解決できました。その理由は、extern "C" を "UnityGetGLViewController" メソッドに追加していなかったからです。コンパイラは C++ 関数としてコンパイルしていましたが、実際には C 関数としてコンパイルする必要があります。

つまり、次のコード スニペットを使用します。

extern "C"
{
    extern UIViewController* UnityGetGLViewController();
}
于 2012-12-12T09:00:35.600 に答える