制作靜態(tài)庫(kù)

  • 制作靜態(tài)庫(kù)


    創(chuàng)建靜態(tài)庫(kù)
  • frameWork 默認(rèn)是動(dòng)態(tài)庫(kù)
    BuildSetting —> 搜索 “Mach” 更改為Static Library

  • 查看支持架構(gòu):lipo -info 靜態(tài)庫(kù)名稱
制作靜態(tài)庫(kù)一般在release 環(huán)境下工作生成的庫(kù)可以支持所有架構(gòu)
4s—>5 :i386
5s—>6plus : x86_64
真機(jī):
3gs —> 4s : armv7 (靜態(tài)庫(kù)只要支持armv7,就可以支持armv7s
5 – > 5c : armv7s
5s —>X :arm64
  • 靜態(tài)庫(kù)合并、分離:
    - 合并:$: lipo -create 庫(kù)1 庫(kù)2 -output 新的路徑
    - 分離:$:lipo [通用庫(kù)] -thin [armv7/arm64] -output [輸出路徑]
  • 靜態(tài)庫(kù) 瘦身 reduce lib size
* 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%.
點(diǎn)擊 target -> build settings -> Generate Debug Symbols ->設(shè)置為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 ->設(shè)置為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的靜態(tài)庫(kù)時(shí),沒(méi)有將
Category的方法鏈接到APP中,造成這個(gè)錯(cuò)誤。具體的細(xì)節(jié)在本文的補(bǔ)充部分展開(kāi)。 

可以看出,解決這個(gè)錯(cuò)誤的方法就是:將Category的方法鏈接到APP中,這樣
APP運(yùn)行時(shí),就能夠找到對(duì)應(yīng)的selector。而 –ObjC就可以完成這個(gè)任務(wù)。"-
ObjC"的作用是:將靜態(tài)庫(kù)中任何Objective-C代碼都鏈接到APP中。任何
Objective-C代碼當(dāng)然也包括Category的方法??梢钥闯觯褂?ObjC可能會(huì)鏈接
很多靜態(tài)庫(kù)中未被使用的Objective-C代碼,極大的增加APP的代碼體積。

"-ObjC" 的兄弟

Flags 位置 作用
-Objc Other Linker Flags 鏈接靜態(tài)庫(kù)中所有的Objective-C代碼
-all_load Other Linker Flags 鏈接靜態(tài)庫(kù)中所有的代碼
-force_load Other Linker Flags 鏈接指定靜態(tài)庫(kù)中所有的代碼
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容