156 Chapter 5
Creating and Using Libraries
Version Control with Shared Libraries
If a shared library lists a second shared library as a dependency, dld.sl
will generate an error if the second shared library has a version number
which is older than the version number recorded with the dependency.
This means that the first library was built using a more recent version of
the second library than the version that dld.sl currently finds.
Adding New Versions to a Shared Library
To rebuild a shared library with new versions of object files, run ld again
with the newly compiled object files. For example, suppose you want to
add new functionality to the routines in length.c, making them
incompatible with existing programs that call libunits.sl. Before
making the changes, make a copy of the existing length.c and name it
oldlength.c. Then change the routines in length.c with the version
directive specifying the current month and date. The following shows the
new length.c file:
#pragma HP_SHLIB_VERSION "11/93" /* date is November 1993 */
/*
* New version of "in_to_cm" also returns a character string
* "cmstr" with the converted value in ASCII form.
*/
float in_to_cm(float in, char *cmstr) /* convert in to cm *
/
{
. . . /* build "cmstr" */
return(in * 2.54);
}
. . . /* other length conversion routines */
To update libunits.sl to include the new length.c routines, copy the
old version of length.o to oldlength.o; then compile length.c and
rebuild the library with the new length.o and oldlength.o:
$ cp length.c oldlength.c Save the old source.
$ mv length.o oldlength.o Save old length.o.
... Make new length.c.
$ cc -Aa -c +z length.c Make new length.o.
$ ld -b -o libunits.sl oldlength.o \ Relink the library.
volume.o mass.o length.o
Thereafter, any programs linked with libunits.sl use the new
versions of length-conversion routines defined in length.o. Programs
linked with the old version of the library still use those routines from
oldlength.o. For details on linking with shared libraries, see Chapter
3, “Linker Tasks,” on page 51.