Changing source file type to Objective-C++ causes linker error when using GameKit

爷,独闯天下 提交于 2019-12-23 10:51:23

问题


So I am using Xcode 6.1 on my Objective-C app. My app uses the GameKit framework.

I tried to call external C++ methods from my GameViewController (which is Objective-C source.)

To make GameViewController.mm compile, I had to set the type to 'Objective-C++ Source' manually.

However, even though the source now compiles, it will fail to link with:

    Undefined symbols for architecture x86_64:
 "_OBJC_CLASS_$_GLKViewController", referenced from:
      _OBJC_CLASS_$_GameViewController in GameViewController.o
  "_OBJC_METACLASS_$_GLKViewController", referenced from:
      _OBJC_METACLASS_$_GameViewController in GameViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I can only get rid of the linker error by setting the type back to 'Objective-C Source' and removing the calls to the external C++ functions.

Why does the linker fail if my source is compiled as 'Objective-C++ Source' instead of 'Objective-C Source' type?

Note that I properly link against GameKit in the Build-phases.


回答1:


OK. It turns out to be a weird one, but:

I was linking to GameKit, and not GLKit. The fix: link to GLKit as well.

Now, the strange part is that not linking GLKit causes no problems if the view controller is built as Objective-C source. It does cause problems if built as Objective-C++ source.

Strange, but true.



来源:https://stackoverflow.com/questions/27139655/changing-source-file-type-to-objective-c-causes-linker-error-when-using-gameki

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!