Development

ar

Create, modify, and inspect Unix archive files.

archivelibraryobject filesdevelopment

Additional Notes

ar works with Unix archive files. It is commonly used to create and inspect static libraries such as libname.a, which contain object files used by compilers and linkers.

It is not the same as tar. Use ar mainly for development artifacts and package internals, not normal backups.

Syntax

ar [operation][modifiers] archive [members...]

Parameters

  • operation: Action such as r, t, x, or d.
  • archive: Archive file, often a .a static library.
  • members: Object files or member names.

Common Operations

  • r: Add or replace members.
  • c: Create archive without warning.
  • s: Write an index, similar to ranlib.
  • t: List archive members.
  • x: Extract members.
  • d: Delete members.
  • v: Verbose output.

Examples

ar rcs libhello.a hello.o util.o

Create or update a static library.

ar t libhello.a

List archive members.

ar x libhello.a

Extract all members.

ar d libhello.a old.o

Delete one member from an archive.

Practical Notes

  • ar archives do not compress data.
  • Static libraries usually need an index; use rcs for common creation.
  • Use nm to inspect symbols inside object files or static libraries.