Kenwood HP 9000 Personal Computer User Manual


 
Chapter 5 133
Creating and Using Libraries
Creating Archive Libraries
cosh.o
Object modules are displayed.
erf.o
fabs.o
floor.o
....
This indicates that the library was built from object files named cosh.o,
erf.o, fabs.o, floor.o, and so forth. In other words, module names
are the same as the names of the object files from which they were
created.
Example of Creating an Archive Library
Suppose you are working on a program that does several conversions
between English and Metric units. The routines that do the conversions
are contained in three C-language files shown:
length.c - Routine to Convert Length Units
float in_to_cm(float in) /* convert inches to centimeters */
{
return (in * 2.54);
}
volume.c - Routine to Convert Volume Units
float gal_to_l(float gal) /* convert gallons to liters */
{
return (gal * 3.79);
}
mass.c - Routine to Convert Mass Units
float oz_to_g(float oz) /* convert ounces to grams */
{
return (oz * 28.35);
}
During development, each routine is stored in a separate file. To make
the routines easily accessible to other programmers, they should be
stored in an archive library. To do this, first compile the source files,
either separately or together on the same command line:
$ cc -Aa -c length.c volume.c mass.c Compile them together.
length.c:
volume.c:
mass.c:
$ ls *.o List the .o files.
length.o mass.o volume.o