2dx-lua Other Linker Flags 设置成 -ObjC 真机编译报错"_GCControllerDidDisconnectNotification"

来源:互联网 发布:炽热狙击网络连接失败 编辑:程序博客网 时间:2024/06/09 22:07

原文地址:http://www.cocoachina.com/bbs/read.php?tid=225869

用的 cocos2dx-lua quick3.3,Other Linker Flags 设置成 -ObjC 时候, 真机无法编译通过
报错如下:

Undefined symbols for architecture armv7s:
  "_GCControllerDidDisconnectNotification", referenced from:
      -[GCControllerConnectionEventHandler observerConnection:disconnection:] in libcocos2dx iOS.a(CCController-iOS.o)
  "_GCControllerDidConnectNotification", referenced from:
      -[GCControllerConnectionEventHandler observerConnection:disconnection:] in libcocos2dx iOS.a(CCController-iOS.o)
  "_OBJC_CLASS_$_GCController", referenced from:
      objc-class-ref in libcocos2dx iOS.a(CCController-iOS.o)
     (maybe you meant: _OBJC_CLASS_$_GCControllerConnectionEventHandler)
ld: symbol(s) not found for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我用的是phones 6.1.3系统, 接入天马广告SDK,这个sdk要求要将Other Linker Flags 设置成 -ObjC。运行后出现如上错误。

--解决方法:

项目->TARGETS->iOS->Build Phases->Link Binary With Libraries

增加库:
GameController.framework

不行的话就增加两个库:

GameController.framework

MediaPlayer.framework

原因参见:http://stackoverflow.com/questions/24844766/linking-errors-when-adding-admob-to-ios-cocos2d-x-3-2

--补充说明:

关于Xcode上的Other linker flags

Targets选项下有Other linker flags的设置,用来填写XCode的链接器参数,如:-ObjC -all_load -force_load等。
还记得我们在学习C程序的时候,从C代码到可执行文件经历的步骤是:
源代码 > 预处理器 > 编译器 > 汇编器 > 机器码 > 链接器 > 可执行文件
在最后一步需要把.o文件和C语言运行库链接起来,这时候需要用到ld命令。源文件经过一系列处理以后,会生成对应的.obj文件,然后一个项目必然会有许多.obj文件,并且这些文件之间会有各种各样的联系,例如函数调用。链接器做的事就是把这些目标文件和所用的一些库链接在一起形成一个完整的可执行文件。
如果要详细研究链接器做了什么,请看:http://www.dutor.net/index.php/2012/02/what-linkers-do/

那么,Other linker flags设置的值实际上就是ld命令执行时后面所加的参数。

下面逐个介绍3个常用参数:
-ObjC:加了这个参数后,链接器就会把静态库中所有的Objective-C类和分类都加载到最后的可执行文件中
-all_load:会让链接器把所有找到的目标文件都加载到可执行文件中,但是千万不要随便使用这个参数!假如你使用了不止一个静态库文件,然后又使用了这个参数,那么你很有可能会遇到ld: duplicate symbol错误,因为不同的库文件里面可能会有相同的目标文件,所以建议在遇到-ObjC失效的情况下使用-force_load参数。
-force_load:所做的事情跟-all_load其实是一样的,但是-force_load需要指定要进行全部加载的库文件的路径,这样的话,你就只是完全加载了一个库文件,不影响其余库文件的按需加载

0 0
原创粉丝点击