问题描述:在升级XCode4.3.2后,由于new iPad授权导致的一系列混乱后,突然发现原来正常的程序一直报错,问题一直出现在DTCoreText库对UIView扩展的category类中。XCode运行到此处中止,报“Thread1 program received signalSIGABRT”信息提示。
解决经过:经过不停的调试,不停的google,不停的纠结后无果。后来突然想起是否之前解决new iPad真机调试时将编译参数改动导致,随后查询资料,在XCode的“building settings"中的"Other Linker Flag"处指定”-ObjC"参数后重新编译运行后问题解决。
问题原因: 对DTCoreText以static library静态库的方式进行引用,-ObjC参数允许编译器链接包含category的DTCoreText静态库。
参考信息:
见Apple Document
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