iOS:Unix:Mac extract info from a static lib regard

2019-06-01 08:50发布

问题:

I have a static library on my Mac and curious to know if the lib was built for armV7s architecture or not? Is any command/tools available to show the supported architectures in this library?

Thank you, Kamran

回答1:

You may use otool for getting that information.

From otool's manpage

-L Display the names and version numbers of the shared libraries that the object file uses. As well as the shared library ID if the file is a shared library.

Example

> otool -L libRaptureXML_universal.a 

Archive : libRaptureXML_universal.a (architecture armv7)
libRaptureXML_universal.a(RXMLElement.o) (architecture armv7):
Archive : libRaptureXML_universal.a (architecture i386)
libRaptureXML_universal.a(RXMLElement.o) (architecture i386):


回答2:

your-mac:~ yourlogin$ file /Path/to/somebinary

/Path/to/somebinary: Mach-O universal binary with 3 architectures
/Path/to/somebinary (for architecture x86_64):    Mach-O 64-bit executable x86_64
/Path/to/somebinary (for architecture i386):      Mach-O executable i386
/Path/to/somebinary (for architecture ppc7400):   Mach-O executable ppc


回答3:

Not disagreeing with the other answers, but here's one more option: use the lipo command.

The Apple man pages for lipo

You can run lipo -info on executables, or libraries. Some examples:

minime:arc username$ lipo -info libarclite_iphonesimulator.a
input file libarclite_iphonesimulator.a is not a fat file
Non-fat file: libarclite_iphonesimulator.a is architecture: i386

minime:iPhone username$ cd HelloWorld.app/
minime:HelloWorld.app username$ lipo -info HelloWorld
Non-fat file: HelloWorld is architecture: armv7