I have a .a file from which I want to get architecture information. Running file myFile.a
results in file.a: current ar archive
. How can I get more information on what architecture the file contains?
5 Answers
You can also skip the ar
command and use readelf, via something like:
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 $
In case it's relevant, here's the other information that you can get from readelf -h
. I just trimmed the above with grep
, obviously:
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
That output is for one of the object files in libxslt.a
, but it gives the same information for each file.

- 35,455
- 10
- 90
- 93
-
2Recommend adding `Machine` to the list there. That'll include info on the specific CPU the object files are made for, rather than just whether it's 32 or 64 bit or whatever. – cHao Sep 18 '10 at 04:46
-
@cHao: Yeah, I just thought of that, too. I'm doing another edit (and I added the entire output of `readelf -h`). – eldarerathis Sep 18 '10 at 04:50
-
Trying to read a Darwin library on Linux produces this error: "readelf: Error: Not an ELF file - it has the wrong magic bytes at the start" – Lane Rettig Apr 27 '23 at 17:22
Use
lipo -info libExample.a
It will Who the architecture it build for. Other functions like otool or file doesn't give the exact answer and sometimes it to verbose to get the correct information.

- 2,219
- 4
- 22
- 32
objdump
is another option:
objdump -a file.a|grep 'file format'

- 278,309
- 50
- 514
- 539
-
2Can not get architecture information (e.g. arm, x86, etc.) by this solution. – Mahler Aug 21 '19 at 09:19
extract the object files from the archive and inspect them with file(1), nm(1), etc.

- 42,753
- 9
- 87
- 112
-
Is there any way to get architecture information without extracting its contents(at least without leaving any residue behind)? – Mike Sep 18 '10 at 04:32
-
@jer, actually, you can do it with either `readelf` or `objdump`. – Matthew Flaschen Sep 18 '10 at 04:47
-
@Matthew, Sorry, my mind was in OSX/iOS mode i'd been answering those questions all night, and didn't read the tag closely enough. Yeah, you are correct. Neither of those tools exist in osx's dev tools (one doesn't make sense on that platform anyway). – jer Sep 18 '10 at 06:22
I would suggest using objdump instead of lipo. objdump provides detailed information than lipo.

- 2,357
- 3
- 28
- 52