如何在Mac OS X上确定静态库(.a)的目标体系结构?

Jus*_*cle 123 iphone macos linker bsd universal-binary

我有兴趣验证是否为ARM或Intel构建了一个给定的iPhone静态库.

它比任何事物都更具好奇心.是否有某种Mac OS X或BSD特定工具来执行此操作?这篇文章在Linux中给出了一个例子.

Vác*_*vík 235

另一种选择是lipo; 它的输出简洁,可读性更高otool.

一个例子:

% 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
%
Run Code Online (Sandbox Code Playgroud)


Log*_*ldo 67

file可能会告诉你.otool当然应该可以.但我file先试试,比如说

logan:/Users/logan% file d2
d2: Mach-O executable ppc
Run Code Online (Sandbox Code Playgroud)

存档示例:

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
Run Code Online (Sandbox Code Playgroud)

  • 根据我的经验,`file`经常失败. (33认同)
  • 关于lipo的答案进一步向下,总是有效. (4认同)
  • 现在在2015年你应该使用lipo.请参阅以下答案. (4认同)
  • 不幸的是,这不适用于多个操作系统版本。 (2认同)

小智 53

如前所述,file并不总是有效.otool -hv -arch all可能是最接近保证工作的东西 - 它为库中的每个目标文件提供架构信息.

例:

% 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
...


sha*_*een 7

如果有人来这里寻找有关如何判断库(或其中的目标文件)是否适用于 Mac Catalyst 的答案,请使用otool -l转储加载命令。查找任何对象的 LC_BUILD_VERSION 部分。Mac Catalyst 由 标识,platform 6而不是platform 1


ble*_*ter 6

此 bash 脚本将帮助您以编程方式将体系结构列表放入变量中。

list_archs.sh:

#! /bin/bash
lipo -info $1 | sed -En -e 's/^(Non-|Architectures in the )fat file: .+( is architecture| are): (.*)$/\3/p'
Run Code Online (Sandbox Code Playgroud)

使用示例:

./list_archs.sh /usr/lib/libc.dylib
x86_64 i386
Run Code Online (Sandbox Code Playgroud)