Skip to content
Latchkey

ar: Usage, Options & Common CI Errors

ar bundles object files into a .a static library that the linker can pull from.

ar builds the .a static libraries you link with -l. The one thing CI cares about is the symbol index: forget the s modifier (or run on a stale archive) and the linker reports undefined references it could actually resolve.

What it does

ar (archiver) creates, modifies, and extracts from ar archives, most commonly static libraries (lib*.a). It stores object files plus an optional symbol index that the linker uses to find which member defines a symbol.

Common usage

Terminal
ar rcs libfoo.a a.o b.o c.o      # create with symbol index
ar t libfoo.a                     # list members
ar x libfoo.a                     # extract members
ar rcs libfoo.a *.o               # rebuild from all objects
nm libfoo.a | head                # inspect symbols

Options

ModifierWhat it does
rInsert/replace members in the archive
cCreate the archive quietly if absent
sWrite/update the symbol index (like ranlib)
tList the table of contents
xExtract members
dDelete members

Common errors in CI

"archive has no index; run ranlib to add one" (or undefined references that only appear when linking a static lib) means the symbol table is missing - always create with ar rcs, or run ranlib libfoo.a afterward. "malformed archive" / "file format not recognized" means the .a is truncated or not an ar archive (a bad partial build). For reproducible builds, use the D modifier (ar rcsD) so timestamps/uids do not vary between runs.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →