首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

使用类别扩展方法编译静态库.a后不可用的有关问题

2012-06-27 
使用类别扩展方法编译静态库.a后不可用的问题http://developer.apple.com/library/mac/#qa/qa1490/_index.

使用类别扩展方法编译静态库.a后不可用的问题

http://developer.apple.com/library/mac/#qa/qa1490/_index.html

?

A:?Why do I get a runtime exception of "selector not recognized" when linking against an Objective-C static library that contains categories?

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.

To resolve this issue, the target linking against the static library must pass the?-ObjC?option to the linker. This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes. Follow these steps to pass?-ObjC?to the linker:

  1. 2006-10-03

    Changed "and" to "an" in order to make the content correct.

    2006-09-25

    New document that describes how to properly build Objective-C static libraries that contain categories on existing classes.


热点排行