HP-UX Linker and Libraries User's Guide
Note that the whole library name was given, and the -l option was not specified. This is because
the library was in the current directory. If you move libunits.a to /usr/lib/hpux32 (IPF 32-bit
mode) or /usr/lib (PA32 mode) before compiling, the following command line works instead:
$ cc -Aa convert.c -lunits
Linking with archive libraries is covered in detail in “Determining How to Link Programs or Libraries
(Linker Tasks)” (page 27).
Replacing, Adding, and Deleting an Object Module
Occasionally you may want to replace an object module in a library, add an object module to a
library, or delete a module completely. For instance, suppose you add some new conversion
routines to length.c (defined in the previous section), and want to include the new routines in
the library libunits.a. You must then replace the length.o module in libunits.a.
Replacing or Adding an Object Module
To replace or add an object module, use the r key (the same key you use to create a library). For
example, to replace the length.o object module in libunits.a:
$ ar r libunits.a length.o
Deleting an Object Module
To delete an object module from a library, use the d key. For example, to delete volume.o from
libunits.a:
$ ar d libunits.a volume.o Delete volume.o.
$ ar t libunits.a List the contents.
length.o mass.o volume.o is gone.
Summary of Keys to the ar(1) Command
When used to create and manage archive libraries, the syntax of ar is:
ar [-] keys archive [modules] ...
IN the syntax, archive is the name of the archive library, modules is an optional list of object modules or
files. See ar(1) for the complete list of keys and options.
Useful ar Keys
Here are some useful ar keys and their modifiers:
Table 21 Useful ar Keys
Descriptionkey
Delete the modules from the archive.d
Replace or add the modules to the archive. If archive exists, ar replaces modules specified on
the command line. If archive does not exist, ar creates a new archive containing the modules.
r
Display a table of contents for the archive.t
Used with the r, this modifier tells ar to replace only those modules with creation dates later
than those in the archive.
u
Display verbose output.v
Extracts object modules from the library. Extracted modules are placed in .o files in the current
directory. Once an object module is extracted, you can use nm to view the symbols in the
module.
x
For example, when used with the v flag, the t flag creates a verbose table of contents - including
such information as module creation date and file size:
Creating Archive Libraries 97