GCControllerDidDisconnectNotification”, referenced from
在使用 Cocos2d-x 3.2 进行开发时,当将“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)
这些报错信息表明,在编译针对armv7s架构时,链接器找不到GCControllerDidDisconnectNotification、GCControllerDidConnectNotification和GCController等符号的定义。
解决办法
要解决这个问题,需要在 Xcode 中添加必要的框架。具体操作步骤如下:
- 打开 Xcode,点击工程目录。
- 选择“Build Phases”选项卡,然后点击“Link Binary With Libraries”。
- 点击该部分下方的加号(
+)按钮。 - 在弹出的库列表中,添加以下两个框架:
MediaPlayer.frameworkGameController.framework
添加这两个框架后,再次尝试真机编译,问题应该就能得到解决。
通过上述步骤,你可以解决在 Cocos2d-x 3.2 中设置“Other Linker Flags”为-ObjC后真机编译失败的问题。