Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contents of a static library

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?

like image 727
Prasoon Saurav Avatar asked Sep 21 '10 03:09

Prasoon Saurav


People also ask

How do I view the contents of a static library?

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.

What is the format of a static library?

A static library, e.g. libfoo. a is not an executable of any kind. It is simply an indexed archive in unix ar format of other files which happen to be ELF object files.

What is use of static library?

In computer science, a static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable.

Do static libraries have dependencies?

If a static library's code contains references to some shared library items, these references will become dependencies in the resulting executable. The same holds if you link a library instead of executable.


1 Answers

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.

like image 143
Prasoon Saurav Avatar answered Oct 05 '22 12:10

Prasoon Saurav