从iPhone静态库中提取对象(* .o)文件 [英] Extract object (*.o) files from an iPhone static library

查看:564
本文介绍了从iPhone静态库中提取对象(* .o)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组 iPhone静态库(a * .a文件),其中我只调用了几个类。
我过去使用AR(使用linux库)从静态库中提取对象文件,删除不需要的对象文件并重新存档。

I have a set of iPhone static libraries (a *.a file) in which I only call a few of the classes from. I have used AR in the past (with linux libraries) to extract the object files from the static library, remove the unwanted object files and rearchive.

但是,当我尝试这个与iPhone编译静态库,我得到以下错误:

However, when I try this with an iPhone compliled static library, I get the following error:

ar: CustomiPhoneLib.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: CustomiPhoneLib.a: Inappropriate file type or format

有谁知道如何从一个iphone编译的静态库提取目标文件?这可能会减少最终的文件大小。

Does anyone know how to extract the object files from an iphone compiled static library? Doing thie could potentially reduce the final file size.

推荐答案

这是因为你的CustomiPhoneLib.a是一个胖库,它包含多个目标体系结构,即iOS上的armv6和armv7。您可以使用 lip 将特定架构提取到另一个.a文件中,使用 ar ranlib 以随意操作它,然后再次使用 lipo 将经过操作的.a文件重新组合到一个.a胖文件中。例如,

That’s because your CustomiPhoneLib.a is a fat library, i.e., a library that contains more than one target architecture, namely armv6 and armv7 on iOS. You can use lipo to extract a specific architecture into another .a file, use ar and ranlib to manipulate it at will, and then use lipo again to recombine the manipulated .a files into a single .a fat file. For instance,

lipo CustomiPhoneLib.a -thin armv6 -output CustomiPhoneLibarmv6.a
lipo CustomiPhoneLib.a -thin armv7 -output CustomiPhoneLibarmv7.a
### use ar and ranlib at will on both files
mv CustomiPhoneLib.a CustomiPhoneLib.a.original
lipo CustomiPhoneLibarmv6.a CustomiPhoneLibarmv7.a -create -output CustomiPhoneLib.a

但是,由于您提到的原因,您不必这样做。如果链接器需要解析一些符号引用,链接器将只从库(.a)中提取对象(.o)文件。因此,如果库包含一个目标文件,其符号从未在链接过程中被引用(即没有有效使用的符号),该目标文件将不会使其进入可执行文件。

However, you don’t have to do this for the reason you’ve mentioned. The linker will only pull object (.o) files from a library (.a) if it needs to resolve some symbol reference. Therefore, if a library contains an object file whose symbols are never referenced during the linking process (i.e., symbols that are not effectively used), that object file won’t make it into the executable.

这篇关于从iPhone静态库中提取对象(* .o)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆