问:
How do I determine the target architecture of static library (.a) on Mac OS X?
I'm interested in verifying if a given iPhone static library has been built for ARM or Intel.
Its more curiosity than anything. Is there some kind of Mac OS X or BSD specific tool to do this? Thispost gives an example in Linux.
方法1:
file will probably tell you. otool certainly should be able to. But I'd try file first, e.g.
logan:/Users/logan% file d2
d2: Mach-O executable ppc
Example with archive:
logan:/Users/logan% file /usr/lib/libMallocDebug.a
/usr/lib/libMallocDebug.a: Mach-O universal binary with 2 architectures
/usr/lib/libMallocDebug.a (for architecture i386): current ar archive random library
/usr/lib/libMallocDebug.a (for architecture ppc): current ar archive
方法2:
Another option is lipo, it's output is brief and more readable that otool's.
Example:
% lipo -info /usr/lib/libiodbc.a
Architectures in the fat file: /usr/lib/libiodbc.a are: x86_64 i386 ppc
% lipo -info libnonfatarchive.a
input file libnonfatarchive.a is not a fat file
Non-fat file: libnonfatarchive.a is architecture: i386
%
As mentioned earlier, file does not always work. otool -hv is probably the closest thing that is guaranteed to work - it gives architecture information for every single object file in the library.
Example:
% otool -hv /sw/lib/libfftw3.a
Archive : /sw/lib/libfftw3.a
/sw/lib/libfftw3.a(align.o):
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
MH_MAGIC_64 X86_64 ALL 0x00 OBJECT 3 336 SUBSECTIONS_VIA_SYMBOLS
/sw/lib/libfftw3.a(alloc.o):
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
MH_MAGIC_64 X86_64 ALL 0x00 OBJECT 3 416 SUBSECTIONS_VIA_SYMBOLS
本文介绍如何在MacOSX上确定静态库(.a)的目标架构,包括验证iPhone静态库是否为ARM或Intel构建的方法。提供了三种实用工具:file、otool及lipo,并附带具体使用案例。
所支持的架构(平台)&spm=1001.2101.3001.5002&articleId=6872678&d=1&t=3&u=5bc205d0ccdb45e898de6413ae67dd65)
1085

被折叠的 条评论
为什么被折叠?



