36

我有一个 .a 文件,我想从中获取架构信息。运行file myFile.a结果在file.a: current ar archive. 如何获得有关文件包含的架构的更多信息?

4

5 回答 5

47

您还可以通过以下方式跳过ar命令并使用readelf

readelf -h <archive>.a | grep 'Class\|File\|Machine'

[00:32:15] /usr/lib $ readelf -h libxslt.a | grep 'Class\|File\|Machine'
File: libxslt.a(attrvt.o)
  Class:                             ELF32
  Machine:                           Intel 80386
File: libxslt.a(xslt.o)
  Class:                             ELF32
  Machine:                           Intel 80386
... #Trimmed this, it goes on a bit
File: libxslt.a(transform.o)
  Class:                             ELF32
  Machine:                           Intel 80386
File: libxslt.a(security.o)
  Class:                             ELF32
  Machine:                           Intel 80386
[00:32:24] /usr/lib $

如果它是相关的,这里是您可以从中获得的其他信息readelf -h。我只是用 修剪了上面的内容grep,显然:

File: libxslt.a(security.o)
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          2548 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         16
  Section header string table index: 13

该输出用于中的一个目标文件libxslt.a,但它为每个文件提供相同的信息。

于 2010-09-18T04:34:12.453 回答
18

采用

lipo -info libExample.a

它将为谁构建它的架构。其他函数,如 otool 或 file 并没有给出确切的答案,有时它很冗长以获取正确的信息。

于 2012-12-13T12:02:37.137 回答
9

objdump是另一种选择:

objdump -a file.a|grep 'file format'
于 2010-09-18T04:45:45.553 回答
1

http://linux.die.net/man/1/ar

从存档中提取目标文件并使用 file(1)、nm(1) 等检查它们。

于 2010-09-18T04:29:42.107 回答
0

我建议使用 objdump 而不是 lipo。objdump 提供比 lipo 更详细的信息。

于 2014-08-01T02:46:46.297 回答