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.
However, there may be instances in which you
need to release a library version that is incompatible with
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 \
ln libfoo.1 libfoo.so
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
to create a link between the name libfoo.1 and
the name libfoo.so.
libfoo.so is the name the link editor,
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 libfoo.so. 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
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 \
ln libfoo.2 libfoo.so
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.