Skip to content
systemcoding.dev
Toolchains

List the members of a static library with ar t

List the object files inside a .a archive with ar t, add v for sizes and dates, and see duplicate member names that ar extracts only one at a time.

1 min read
Summarize in AI

A static library is an archive of object files, and ar t is its table of contents. It is the first thing to run when a link pulls in more code than you expected, or when you want to know whether a library has the object you need.

Shell
ar t libutil.a
ar tv libutil.a
Text
strutil.o
mathutil.o
rw-r--r-- 0/0   1248 Jan  1 00:00 1970 strutil.o
rw-r--r-- 0/0   1096 Jan  1 00:00 1970 mathutil.o

The verbose form shows permissions, owner and group, size, date and name. Zeroes for owner and the 1970 date mean the archive was built in deterministic mode, which is what reproducible builds want.

Archives allow two members with the same name, and ar t then prints the name twice. That happens when a build script appends objects from two directories that each hold a util.o. Extracting by name gets only the first one, and you pick the second with the N modifier, for example ar xN 2 libutil.a util.o. The linker does not care, since it works from the symbol index and pulls in whichever member defines a needed symbol.

ar t shows members, not symbols. To see which symbols each member holds, use nm -A or nm -s. Both tools are documented in the ar manual, and the dates shown depend on how the archive was built.

Share

More snippets

Systems Programming

Get the page size with sysconf(_SC_PAGESIZE)

Read the memory page size at run time with sysconf(_SC_PAGESIZE) instead of hard-coding 4096, which is wrong on arm64 kernels built with 16K or 64K pages.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.