duplicate symbol错误

2017-06-09  本文已影响28人  HAPPY小元宝

问题:项目中今天引入第三方库报错,报错如下图:

Snip20170609_1.png

解决办法:错误显示是duplicate symbol,于是前往项目Build Settings -> Other Linker Flags中删除掉之前添加的 -all_load,项目恢复正常。

Xcode中Other Linker Flags的作用:

    源代码 -> 预处理器 -> 编译器 -> 汇编器 -> 机器码 ->链接器 -> 可执行文件

在最后一步需要把 .o 文件和 C 语言运行库链接起来,这时候需要用到 ld 命令。源文件经过一系列处理以后,会生成对应的 .obj 文件,然后一个项目必然会有许多 .obj 文件,并且这些文件之间会有各种联系。链接器就是把这些目标文件和所用的一些库链接在一起形成一个完整的可执行文件。
那么,Other Linker Flags 设置的值实际上就是 ld 命令执行时后面所加的参数。
苹果官方的一段话:
The “selector not recognized” runtime exception occurs due to an issue between the implementation of standard UNIX static libraries, the linker and the dynamic nature of Objective-C. Objective-C does not define linker symbols for each function (or method, in Objective-C) - instead, linker symbols are only generated for each class. If you extend a pre-existing class with categories, the linker does not know to associate the object code of the core class implementation and the category implementation. This prevents objects created in the resulting application from responding to a selector that is defined in the category.

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

上一篇下一篇

猜你喜欢

热点阅读