ar(1) ar(1)
NAME
ar - maintains a library of files in an archive
SYNOPSIS
ar -dp [l] [v] archive file...
ar -mp [l] [v] [position archivefile] archive file...
ar -qp [c] [l] [v] archive file...
ar -rp [c] [l] [u] [v] [position archivefile]
archive file...
ar -tp [s] [v] archive file...
ar -xp [l] [s] [v] archive file...
ARGUMENTS
archive
Specifies the name of the archive to be created or
maintained.
-c Causes ar to create an archive without displaying a
message. This option is useful only when used in
combination with the -r and -q options.
-d Deletes the named files from the archive.
file Specifies the name of a file that is to be added to the
archive or that is already in the archive.
-l Causes ar to place its temporary files in the current
directory rather than in the default /tmp. This option
is useful only when used in combination with the -d,
-m, -q, -r, and -x options.
-m Moves the named files to the end of the archive by
default. You can combine this option with a position
specifier to move the file before or after a file that
is already in the archive.
-p Prints the contents of files that are in the archive as
specified by file.
position archivefile
Specifies the position specifiers, where archivefile is
the name of a file in the archive. Replace position
with one of these options:
-a Moves the named files after archivefile.
-b Moves the named files before archivefile.
January 1992 1
ar(1) ar(1)
-i Inserts the named files before archivefile. This
action is identical to the action of the -b
position specifier.
-q Appends the named files to the end of the archive. If
the archive does not exist, ar creates it and displays
the message ar: creating archive. You cannot use a
position specifier, as described for the -m option,
with this option. The -q option does not check whether
the named file is already in the archive and therefore
can add duplicates. This option is used to avoid
quadratic behavior when creating a large archive on a
file-by-file basis. For an alternative to the -q
option, see the -r option.
-r Replaces the named file in the archive. If the named
file is not already in the archive, ar adds the file to
end of the archive unless you also use a position
specifier, as described for the -m option. If the
archive does not exist, ar creates it and displays the
message ar: creating archive.
-s Causes ar to regenerate the archive's symbol table. The
-d, -m, -q, -r, and -u options cause ar to regenerate
the symbol table automatically. The other options do
not. You can use this option in conjunction with the
-p, -t, and -x options to restore the symbol table,
when, for example, strip has been used on the archive.
-t Prints the name of each named file in the archive. If
you do not specify any names, ar prints the names of
all files in the archive. Typically, you use this
option with the -v option.
-u Changes the behavior of the -r option by causing ar to
replace only those files whose modification dates are
more recent than the modification date of the archive.
-v Causes ar to give a file-by-file description as it
works. When used with the -t option, ar prints a
listing similar to the output of the ls(1) command for
each file in the archive.
-x Extracts a copy of the named file. If you do not
specify a name, ar extracts all files in the named
archive. In either case, this option does not alter
the archive.
DESCRIPTION
ar maintains files in a single file that is called an
``archive.'' Typically, an archive is a library of object
files that is used by the link editor, ld, to resolve
2 January 1992
ar(1) ar(1)
references so that it can produce an executable file. You
can also use ar to create and maintain libraries of other
file types.
When ar creates an archive, headers are created in a format
that is portable across all machines. The portable archive
format and structure are described in detail in ar(4). The
archive symbol table (described in ar(4)) is used by the
link editor (ld) to do multiple passes over libraries of
object files efficiently. Whenever you use ar to create or
update an archive, ar rebuilds the symbol table. You also
can use the -s option to rebuild the symbol table.
EXAMPLES
The first example replaces the file foo.o in the archive
libfoo.a with a new copy of foo.o:
ar -rc libfoo.a foo.o
If libfoo.a does not exist, ar creates it. The -c option
prevents ar from issuing a message that it has created the
archive. Because the command does not use a position
specifier, ar places foo.o at the end of the archive if
foo.o is not already in the archive.
The second example uses the -u option to cause ar to update
the archive using only those files in the current directory
that have a .o suffix and that are newer than the
modification date of the archive itself:
ar -ru libfoo.a *.o
The third example inserts the file new.o into the archive
libfoo.a before foo.o, which is already in the archive:
ar -rvb foo.o libfoo.a new.o
The -v option causes ar to print a message as it adds new.o.
LIMITATIONS
If you specify the same file more than once in an argument
list, ar puts the file in the archive once for each mention.
FILES
/bin/ar
Executable file
/tmp/ar*
Temporary files
SEE ALSO
ld(1), lorder(1), strip(1), tar(1)
January 1992 3
a.out(4), ar(4) in A/UX Programmer's Reference
4 January 1992