Kenwood HP 9000 Personal Computer User Manual


 
134 Chapter 5
Creating and Using Libraries
Creating Archive Libraries
Then combine the .o files by running ar with the r key, followed by the
library name (say libunits.a), followed by the names of the object files
to place in the library:
$ ar r libunits.a length.o volume.o mass.o
ar: creating libunits.a
To verify that ar created the library correctly, view its contents:
$ ar t libunits.a Use ar with the t key.
length.o
volume.o
mass.o All the .o modules are included; it worked.
Now suppose you've written a program, called convert.c, that calls
several of the routines in the libunits.a library. You could compile the
main program and link it to libunits.a with the following cc
command:
$ cc -Aa convert.c libunits.a
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 before compiling, the following
command line will work instead:
$ cc -Aa convert.c -lunits
Linking with archive libraries is covered in detail in Chapter 3, “Linker
Tasks,” on page 51.
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 would then have to 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