Building Objective-C static libraries with categories
来源:互联网 发布:图片文档识别软件 编辑:程序博客网 时间:2024/05/20 21:57
Building Objective-C static libraries with categories
Q: Why do I get a runtime exception of "selector not recognized" when linking against an Objective-C static library that contains categories?
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.
// 这种链接和Object-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.
// Objective-c 不为每一个函数(方法,在Object-C)定义连接元素,换句话说,连接元素仅仅在每个类产生。
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.
// 目标链接静态库,必须传一个-Objc指针 指向连接器
This flag causes the linker to load every object file in the library that defines an Objective-C class or category.
// 这个标记 引起链接器 去加载每个定义一个定义了Object-c类或类目的在静态库中的对象文件。
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.
// 它将允许成功的创建有效的Objective-C静态库-在已存在类上类目
Follow these steps to pass -ObjC
to the linker:
// 通过这两步去传一个objc到连接器
In Xcode, double-click the target's name under "Targets" in the Project window.//在Xcode双击 在工程窗口 Targets下的target
Choose the Build pane from the ensuing Info window.//
Scroll down to the
Other Linker Flags
build setting under the Linking collection and set its value to-Obj
Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC
from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the -all_load
or -force_load
flags.
-all_load
forces the linker to load all object files from every archive it sees, even those without Objective-C code. -force_load
is available in Xcode 3.2 and later. It allows finer grain control of archive loading. Each -force_load
option must be followed by a path to an archive, and every object file in that archive will be loaded.
- Building Objective-C static libraries with categories
- Building Objective-C static libraries with categories
- Objective-C static libraries with categories
- Objective-C categories in static library
- Objective-C categories in static library
- Faking instance variables in Objective-C categories with Associative References
- Monkey-Patching iOS with Objective-C Categories Part III: Swizzling
- Objective-C: Categories
- Categories in Objective-C
- Objective-C:Categories
- Building C/C++ libraries with Automake and Autoconf
- 用Xcode&iPhone SDK 创建一个static library (Building static libraries with the iPhone SDK)
- [Objective-C] Categories 小例子
- Objective-C categories in static library链接库真实链接的大小
- Objective-C 中Categories 初体验
- Objective-c的Categories和protocols
- objective-c的categories(分类)
- Ry’s Objective-C Tutorial---Categories
- An introduction to JAX-RS and JAXB
- Git 相关
- 漫谈重构
- java表达式类型的自动提升
- Spring 的 init-method 和 destory-method
- Building Objective-C static libraries with categories
- 如何在VC中使用GDI+
- struts2中对于default-action-ref配置的解析思路
- go语言之bufio 打开文件,读取一行
- 静态链接libcurl的步骤
- Jquery实现网页右下角弹窗
- 因子和阶乘
- 长方柱的体积和表面积
- FPGA引脚信号分配的几个原则