Re: Using a specific version of a dynamic library - how?

From: Paul Pluzhnikov (
Date: 05/08/04

Date: 08 May 2004 11:17:17 -0700 (Thomas Aho) writes:

> Is there a way to link my application in a way, which makes it select
> a certain version of a dynamic library at run-time?


> Say for example that I write an application and use qt 3.1.2. I want
> to be

[Fix your line wrapping, will you ... It's ugly]

> able to install the binary on a server from where everyone in my
> organization
> can run it. A precondition is then of course that they have the
> or somewhere in their LD_LIBRARY_PATH.
> The problem is that if there is also a newer version of qt installed
> on their
> system, /usr/lib/ will be linked to for example
> When
> starting my application, it will load the 3.2.2 version of qt-mt,
> which fails.

That is not supposed to happen: if 3.2.2 is not compatible with
3.1.2, it is supposed increment its "external version".

What exactly is the failure? Are you sure it is not caused by a
bug in your app?

> What I simply would like to do is to link my application in a way
> which makes
> it "look for 3.1.2; if there is no 3.1.2, look for 3.1; if there is no
> 3.1, look for 3, ...".

That is impossible, I think.

What you can do is link it in such a way that it explicitly looks
for 3.1.2; or 3.1; or 3 (which is what it is probably doing now).

Begin by finding out what is currently recorded as the application
dependency: 'objdump -p exename | grep NEEDED | grep libqt' will
probably print:


Then read up on "external library versioning", here is one place:

> Is it possible to do what I want?

If you want to bind your app to e.g. libqt-mt-so.3.1, you'll have
to build yourself a "custom" copy of The very
last command in the build looks something like:

  g++ -shared ... -o -Wl,-soname, ...

Change the soname part to, relink your app against
the new you just built, and presto.


In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

Relevant Pages