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文件