C compilation system


Allocating buffers dynamically can ease the job of library maintenance. As a general rule, ensure that updated versions of a dynamically linked library are compatible with its previous versions so that users do not have to recompile their applications.

NOTE: Avoid changing the names of library symbols from one release to the next.

However, there may be instances in which you need to release a library version that is incompatible with its predecessor. On the one hand, you will want to maintain the older version for dynamically linked executables that depend on it. On the other hand, you will want newly created executables to be linked with the updated version. Moreover, you will probably want both versions to be stored in the same directory. In this example, you could give the new release a different name, rewrite your documentation, and so forth. A better alternative would be to plan for the contingency in the first instance by using the following sequence of commands when you create the original version of the dynamically linked library:

cc -dy -K PIC -G -h libfoo.1 -o libfoo.1 function1.c \
function2.c function3.c
ln libfoo.1

In the first command -h stores the filename given to it, libfoo.1, in the dynamically linked library itself. You then use the UNIX operating system command ln(C) to create a link between the name libfoo.1 and the name is the name the link editor, ld(CP), looks for when users of your library specify:

cc -dy -Ldir file1.c file2.c file3.c -lfoo

However, the link editor records in the user's executable the name you gave to -h, libfoo.1, rather than the name That means that when you release a subsequent, incompatible version of the library, libfoo.2, executables that depend on libfoo.1 continues to be linked with it at run time.

As shown earlier, the dynamic linker uses the filename of the dynamically linked library that is stored in the executable to satisfy unresolved external references at run time.

You use the same sequence of commands when you create libfoo.2:

cc -dy -K PIC -G -h libfoo.2 -o libfoo.2 function1.c \
function2.c function4.c
ln libfoo.2

When users specify:

cc -dy -L dir file1.c file2.c file3.c -lfoo

the filename libfoo.2 is stored in their executables, and their programs are linked with the new library version at run time.

Next topic: Multiply defined symbols
Previous topic: Minimize paging activity

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003