help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Clearing/resetting g++/ld linker path for each -l


From: Paul Pluzhnikov
Subject: Re: Clearing/resetting g++/ld linker path for each -l
Date: Fri, 18 May 2007 07:11:18 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

Andy Buckley <andy@insectnation.org> writes:

> I'd like to know if it's possible to clear the ld library search path
> within a single linker call.

I don't believe so. Also your question is about the linker; it has
nothing to do with gcc/g++, and can't be answered without knowing
which linker you are using. *Do* tell about your environment
next time. Assuming Linux / GNU-ld for now.

> Specificlly, the problem is that I have
> two libraries A and B, and there's a version of each in two include
> paths, say /usr/lib and/usr/local/lib. So we've got /usr/lib/libA.so, /
> usr/lib/libB.so, /usr/local/lib/libA.so and /usr/local/lib/libB.so.

Ok, you've got a screwed-up system ...

> Now I want to link against the version of library A from /usr/lib and
> the version of B from /usr/local/lib. Unfortunately this command line
> doesn't work:
>
> g++ ... -L/usr/lib -lA -L/usr/local/lib -lB

I think your only choice is to do this:

  g++ ... /usr/lib/libA.so /usr/local/lib/libB.so

Even though this will do what you want at static link time, it may
or may not do what you want at runtime (depending on whether SONAME
is set in lib{A,B}.so).

> ? I'm using autotools and libtool if that's any help.

Autotools will hinder rather than help you.

> If there's no
> way of doing that, is there any other technique which will avoid me
> needing to rewrite a large chunk of our build system's m4 macros to
> work out absolute paths for every library?

The way to fix the problem is not to install conflicting versions
into /usr/local/lib and /usr/lib. Install non-system versions of
lib{A,B}.so into /usr/local/lib/lib{A,B}-v1/ and you would be
able to control which version of which library you pick up:

  g++ ... -lA -lB                             # use system defaults
  g++ ... -L/usr/local/lib/libA-v1 -lA -lB    # /usr/local/.../libA.so
  g++ ... -lA -L/usr/local/lib/libB-v1 -lB    # /usr/local/.../libB.so
... etc ...

Note: if lib{A,B}.so have SONAME set (which arguably they should,
since there are multiple incompatible versions), the picture grows
even more complicated. The good news: if SONAME is set with proper
version info, e.g. libA.so.1.2 for /usr/local/lib/libA.so and 
libA.so.1.1 for /usr/lib/libA.so (and similar SONAMEs for libB.so),
then you can do what you want quite easily:

  ln -s /usr/lib/libA.so .          &&
  ln -s /usr/local/lib/libB.so .    &&
  g++ ... -L. -lA -lB               &&
  rm -f libA.so libB.so

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]