Shared libraries

Linking to older versions of a library

By providing a specific *.so file

Some pieces of software require linking to old versions of libraries. In most cases, the development package provides a .so symlink for the newest version of the library. For example:

/opt/csw/include/foo.h
/opt/csw/lib/libfoo.so.0
/opt/csw/lib/libfoo.so.1
/opt/csw/lib/libfoo.so --> libfoo.so.1

In this setup, it is not possible to link against libfoo.so.0. In most cases it's intended, but there are cases, such as berkeleydb, in which linking against an old version is necessary. In such case, the following setup solves the problem:

/opt/csw/include/foo.h
/opt/csw/include/foo-old/foo.h
/opt/csw/lib/libfoo.so.0
/opt/csw/lib/libfoo.so.1
/opt/csw/lib/libfoo.so --> libfoo.so.1
/opt/csw/lib/foo-old/libfoo.so --> ../libfoo.so.0

In order to link against the old version of libfoo (and use its corresponding headers), the -I/opt/csw/include/foo-old flag needs to be passed before the -I/opt/csw/include flag, and -L/opt/csw/lib/foo-old needs to be passed before -L/opt/csw/lib.

In the default case, including only the standard -I and -L flags results in linking to the newest version of the library. This way, the default case is easy, and the hard case is possible.

By providing separate lib directories

In this solution, the old library is delivered in a separate directory. Some packages deliver files into /opt/csw/<custom-dir>:

/opt/csw/foo-0/include/foo.h
/opt/csw/foo-0/lib/libfoo.so.0
/opt/csw/foo-0/lib/libfoo.so --> ../libfoo.so.0
/opt/csw/foo-1/include/foo.h
/opt/csw/foo-1/lib/libfoo.so.1
/opt/csw/foo-1/lib/libfoo.so --> libfoo.so.1

In this solution, client software, in order to link against any version of libfoo, must use custom -I, -L and -R flags, pointing at a specific version of the library.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License