lipo指令是Mac上的一款處理Binaries的工具,大致哪些用法在終端輸入lipo查看:
-archs
-create [-arch_blank <arch_type>]
-detailed_info
-extract <arch_type> [-extract <arch_type> ...]
-extract_family <arch_type> [-extract_family <arch_type> ...]
-info
-remove <arch_type> [-remove <arch_type> ...]
-replace <arch_type> <file_name> [-replace <arch_type> <file_name> ...]
-thin <arch_type>
-verify_arch <arch_type> ...
options are one or more of:
-arch <arch_type> <input_file>
-hideARM64
-output <output_file>
-segalign <arch_type> <alignment>
lipo -info xxx,查看當前可執行文件的架構組成,是否是胖二進制,由哪些CPU架構組成。
Non-fat file: xxxx is architecture: x86_64 arm64
lipo -thin ,從胖二進制可執行文件中剝離出想要的CPU架構,例如下面是剝離x86_64, 生成xxx_x86_64可執行文件
lipo -thin x86_64 xxx -output xxx_x86_64
-> xxxxx $ lipo -info xxx_x86_64
Non-fat file: xxx_x86_64 is architecture: x86_64
lipo -remove,從胖二進制可執行文件移除不想要的CPU架構,這個和lipo -thin非常相似,不同點是剝離出去的架構,依然是胖二進制類型。例如下面生成的xxx_arm64可執行文件,用lipo -info查看依然是胖二進制可執行文件 fat file
lipo -remove arm64 xxx -output xxx_arm64
-> xxxxx $ lipo -info xxx_arm64
Architectures in the fat file: xxx_arm64 are: arm64
lipo -create 合併二進制
lipo -create a二進制 b二進制 -output c二進制
lipo -remove執行結果,會導致在執行ar -x 指令的時候無法執行 報錯如下:
ar: libBBAVendorAd_arm64 is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: libBBAVendorAd_arm64: Inappropriate file type or format
必須使用Non-fat file纔可以,補充ar -x指令是摘取可執行文件內部的文件組成,例如在iOS中就是拿到可執行文件內部的所有.o文件