Extract object (*.o) files from an iPhone static library

前端 未结 2 558
星月不相逢
星月不相逢 2021-01-30 11:35

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 extrac

2条回答
  •  走了就别回头了
    2021-01-30 11:51

    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
    

    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.

提交回复
热议问题