2012-10-22 44 views
1

在我的靜態庫項目(目標:sdk.a),我用這樣一個外部函數:爲什麼我在項目中看不到外部功能?

// 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(); 
} 

在一個名爲團結,iPhone.xcodeproj另一個項目,我用了SDK.a。 而且還有一個名爲AppController.mm文件包含下面的代碼:

static UIViewController* sGLViewController = nil; 
UIViewController* UnityGetGLViewController() 
{ 
    return sGLViewController; 
} 
static UIView* sGLView = nil; 
UIView* UnityGetGLView() 
{ 
    return sGLView; 
} 

當我建立統一,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) 

這兩個函數是在AppController.mm中真正定義的但爲什麼我在鏈接時找不到它? Unity-iPhone.xcodeproj的另一個連接器標誌如下:

-all_load -weak_framework CoreMotion -weak-lSystem 

回答

3

我能解決這個問題。原因是我沒有添加extern「C」到「UnityGetGLViewController」方法。編譯器將其編譯爲C++函數,但實際上它必須編譯爲C函數。

即使用下面的代碼片段

extern "C" 
{ 
    extern UIViewController* UnityGetGLViewController(); 
} 
相關問題