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

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


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.alipo CustomiPhoneLib.a -thin armv7 -output CustomiPhoneLibarmv7.a### use ar and ranlib at will on both filesmv CustomiPhoneLib.a CustomiPhoneLib.a.originallipo 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.


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

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