Wednesday 19 March 2008

Linking to different versions of a dynamic library

On Linux there's loads of [dynamic ".so"] libraries in places like /usr/lib. The libraries have version numbers; Major version indicates major (API) changes, whilst the minor version typically relates to bug fixes. These version numbers are firstly enshrined with the library using a special symbol (SONAME) - which is assigned on library creation (using the -soname arg to ld). Also libraries are named with their version numbers libsomething.so.2.3. You can verify this using:
objdump -p libsomething.so.2.3* | grep SONAME

So if you're developing and you want to link to specific version what do you do? Well basically there's no neat trick to get the linker (ld) to link a specific version at compile time :( so you can either:
  • Link using the full path to the specific library version
  • Create a softlink/symlink (ending in ".so" - with NO version) to the specific library version
ldconfig does do some stuff related creating links for libraries but as explained here it won't create the plain ".so" necessary for development - these are usually included as part of a "dev" (usually suffixed by "-dev") package on your system (be it Debian or Red Hat or whatever).