“Replacing, Adding, and Deleting an Object Module” (page 97)

“Summary of Keys to the ar(1) Command” (page 97)

“Archive Library Location (IPF) ” (page 98)

Overview of Creating an Archive Library

To create an archive library:

1.Create one or more object files containing relocatable object code. Typically, each object file contains one function, procedure, or data structure, but an object file can have multiple routines and data.

2.Combine these object files into a single archive library file with the ar command. Invoke ar with the r key.

("Keys" are like command line options, except that they do not require a preceding -.)

Figure 9 (page 95) summarizes the procedure for creating archive libraries from three C source files (file1.c, file2.c, and file3.c). The process is identical for other languages, except that you use a different compiler.

Figure 9 Creating an Archive Library

Contents of an Archive File

An archive library file consists of four main components:

1.A header string, "!<arch>\n", identifying the file as an archive file created by ar (\n represents the newline character)

2.A symbol table, used by the linker and other commands to find the location, size, and other information for each routine or data item contained in the library

3.An optional string table used by the linker to store file names that are greater than 15 bytes long (only created if a long file name is encountered)

4.Object modules, one for each object file specified on the ar command line

To see what object modules a library contains, run ar with the t key, which displays a table of contents. For example, to view the "table of contents" for libm.a:

$ ar t /usr/lib/hpux32/libm.a

//Run ar with the t key.

Creating Archive Libraries

95