Contents of a static library
Asked Answered
N

5

78

I have a static library, say mystaticlib.a. I want to see its contents, such as the number of object files inside it.

How can I do this on gcc?

Neidaneidhardt answered 21/9, 2010 at 3:31 Comment(1)
Is there any way to do it in python?Velvetvelveteen
N
110

On gcc, use ar -t.

-t option of the gnu archiver (ar) writes a table of contents of archive to the standard output. Only the files specified by the file operands shall be included in the written list. If no file operands are specified, all files in archive shall be included in the order of the archive.

More info here.

Neidaneidhardt answered 21/9, 2010 at 3:32 Comment(1)
Thank you. So, ar -x libdlib.a indeed extracted out every *.o without mercy. ExcellenceTerribly
A
74

You can see the contents (the .o files that went into it) and the defined symbols by using nm. If this contains C++ code you should use the -C option to demangle the symbol names:

nm -C libschnoeck.a | less
Anamorphic answered 21/9, 2010 at 9:8 Comment(0)
D
19

On a Mac, simply use

nm libschnoeck.a | less

There is no -C option with the Mac version of nm.

Damali answered 23/1, 2014 at 22:34 Comment(0)
I
3

It just stumbled over this:

You can open an archive (.a) with 7zip. Also works for the object files in the archive. Listing all sorts of contents like .text, .bss, .data, etc. with their offset, length, type, ... Furthermore its possible to unpack all, using a hex editor or notepad++ to view the contents. I tested this with an archive created with GNUToolsARMEmbedded\2018-q4-major\bin\arm-none-eabi- Toolchain and 7Zip 16.04 (64-bit)

Imminence answered 21/8, 2019 at 8:43 Comment(0)
C
1

I just discovered that you can use readelf -a to display the contents of all the object files in a static library.

Invoke the readelf command like this: $ readelf -a mystaticlib.a.

Circumscription answered 1/9, 2021 at 17:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.