【问题标题】:Why I can't see the extern function in the project?为什么我在项目中看不到extern函数?
【发布时间】:2012-10-11 21:09:10
【问题描述】:

在我的静态库项目(target: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();
}

在另一个名为 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)

这两个函数确实是在AppController.mm中定义的,但是为什么链接的时候找不到呢? Unity-iPhone.xcodeproj 的另一个链接器标志如下:

-all_load -weak_framework CoreMotion -weak-lSystem

【问题讨论】:

    标签: xcode static symbols


    【解决方案1】:

    我能够解决这个问题。原因是我没有将 extern "C" 添加到 "UnityGetGLViewController" 方法中。编译器将其编译为 C++ 函数,但实际上它必须编译为 C 函数。

    即使用以下代码 sn-ps

    extern "C"
    {
        extern UIViewController* UnityGetGLViewController();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-27
      • 2017-11-13
      • 1970-01-01
      • 2020-09-09
      • 2022-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多