2

I was wondering if it's possible to have multiple instances of a library in Linux.

Example :

  • Software A need the 1.0, 1.1 or 1.2 branch or older of Library X to work
  • Software B need the 1.4 branch or any newer 1.x of Library X to work
  • Software C need the 2.0 branch or newer of Library X to work

Is it possible to install the 1.2, 1.8 and 2.3 of Library X to make all this 3 software work?

2

Can you install multiple versions of a single library?

Yes, definitely! Package management under *nix actually makes this very simple. The only thing it will require is that the packages do not conflict (which means a couple tricks might need to be done by the packager). But, your real question requires a more in-depth answer.

Would installing multiple versions of a library like this make software using the different versions work properly?

Maybe. It depends on how each piece of software links to the required library. For example, if you take a look in /usr/lib, you'll notice that most libraries have at least two different files in this directory (libname.so and libname.so.#.#.# where # is a number). You will likely notice that libname.so is usually a symlink to the second file. Typically speaking, this is because software can choose to either link to a specific version of a library, or link to whatever version of the library is unversioned (usually the latest version).

Now, if each of the pieces of software has such specific requirements for which version of the library it uses, they may each choose directly to the version they need (rather than hoping that the unversioned library is the one they want). If this is the case, then you're probably home free, and all you need to do is have the different library versions installed correctly. If, however, one of these pieces of software links to the unversioned link but expects it to be a particular version of the library, it will act up unless the unversioned link happens to be the version they expect.

Let's use an example to demonstrate. Under Arch Linux, two versions of libpng are officially packaged (1.2 and 1.6). I happen to have both installed.

$ ls -l /usr/lib | grep png
lrwxrwxrwx  1 root root    18 Mar 12 08:05 libpng12.so -> libpng12.so.0.51.0*
lrwxrwxrwx  1 root root    18 Mar 12 08:05 libpng12.so.0 -> libpng12.so.0.51.0*
-rwxr-xr-x  1 root root  168K Mar 12 08:05 libpng12.so.0.51.0*
lrwxrwxrwx  1 root root    19 Jun 27 19:53 libpng16.so -> libpng16.so.16.12.0*
lrwxrwxrwx  1 root root    19 Jun 27 19:53 libpng16.so.16 -> libpng16.so.16.12.0*
-rwxr-xr-x  1 root root  216K Jun 27 19:53 libpng16.so.16.12.0*
lrwxrwxrwx  1 root root    11 Jun 27 19:53 libpng.so -> libpng16.so*

Now, looking at this set of files, you'll notice that libpng.so (the completely unversioned link) points to libpng16.so (a versioned link with no soname) which points to libpng.so.16.12.0. So, if a piece of software chooses to link to libpng.so, then on my system, it's going to link to libpng.so.16.12.0; and, hopefully, that's what that piece of software expects. However, if that piece of software actually expects a version of 1.2, there are going to be issues.

The conclusion here is, if you are packaging the software, figure out what hard requirements it has for library versions, and make sure that during the compilation step, it links to the right one. If you are a developer, the lesson is that you should either try to keep your software up-to-date with the latest version of all libraries you link to (so that you can just link straight to libname.so and probably be fine), or figure out what things you depend on, and require linking only to versions of the library that support it.

  • Thank you for your answer. I suppose that the "16.12.0" of "libpng16.so.16.12.0" is the version number, isn't it? – Dremor Aug 28 '14 at 15:56
  • 1
    Indeed. (Though, be aware that projects can choose their own versioning standards, so that might not always be the case—though I'm unsure of what else it might be in such a case.) – HalosGhost Aug 28 '14 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.