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

前端 未结 2 559
星月不相逢
星月不相逢 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.

    0 讨论(0)
  • 2021-01-30 11:55

    Code: ar -t mylib.a This will list all of the files in the archive.

    Code: ar -xv mylib.a myobj.o This will extract the object give myobj.o from the library mylib.a.

    0 讨论(0)
提交回复
热议问题