制作静态库

2018-06-15  本文已影响0人  Install_be
制作静态库一般在release 环境下工作生成的库可以支持所有架构
4s—>5 :i386
5s—>6plus : x86_64
真机:
3gs —> 4s : armv7 (静态库只要支持armv7,就可以支持armv7s
5 – > 5c : armv7s
5s —>X :arm64
* make sure that you set Generate Debug Symbols to NO in your build settings. This can reduce the size of your static library by about 30%.
点击 target -> build settings -> Generate Debug Symbols ->设置为NO

* In your target's build settings look for 'Optimization Level'. By switching that to 'Fastest, Smallest -Os' you'll permit the compiler to sacrifice some speed for size.
击 target -> build settings -> Optimization Level ->设置为Fastest, Smallest -Os

Technical Q&A QA1490 :
"An impedance mismatch between UNIX static libraries and the dynamic nature 
of Objective-C can cause category methods in static libraries to not be linked 
into an app, resulting in "selector not recognized" exceptions when the methods 
aren't found at runtime."

这段话的意思就是:链接器在处理包含Category方法的UNIX的静态库时,没有将
Category的方法链接到APP中,造成这个错误。具体的细节在本文的补充部分展开。 

可以看出,解决这个错误的方法就是:将Category的方法链接到APP中,这样
APP运行时,就能够找到对应的selector。而 –ObjC就可以完成这个任务。"-
ObjC"的作用是:将静态库中任何Objective-C代码都链接到APP中。任何
Objective-C代码当然也包括Category的方法。可以看出,使用-ObjC可能会链接
很多静态库中未被使用的Objective-C代码,极大的增加APP的代码体积。

"-ObjC" 的兄弟

Flags 位置 作用
-Objc Other Linker Flags 链接静态库中所有的Objective-C代码
-all_load Other Linker Flags 链接静态库中所有的代码
-force_load Other Linker Flags 链接指定静态库中所有的代码
上一篇 下一篇

猜你喜欢

热点阅读