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
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 symbolsOptions
| Modifier | What it does |
|---|---|
| r | Insert/replace members in the archive |
| c | Create the archive quietly if absent |
| s | Write/update the symbol index (like ranlib) |
| t | List the table of contents |
| x | Extract members |
| d | Delete 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.