For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > June 2005 > Augmenting LD_LIBRARY_PATH at runtime









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Augmenting LD_LIBRARY_PATH at runtime
Ashu

2005-06-02, 9:02 am

Is there a way to augment the LD_LIBRARY_PATH at runtime, or achieve the
same effect through any other means?
(setenv("LD_LIBRARY_PATH",...) does not work at runtime).

The problem faced is this:

Library libABC.so is linked against libXYZ.so, and both are finally kept in
the same directory.
An application knows the location of libABC.so and dlopen()s it (giving the
full path). The call, however, fails because the directory containing
libXYZ.so is not in LD_LIBRARY_PATH and so libXYZ.so can not be found.

Is there a way to dlopen libABC.so although LD_LIBRARY_PATH is inadequate as
regards the location of libXYZ.so?

The application is a third-party one, and so I cannot modify its launch
behaviour (such as wrapping it in a script which first sets LD_LIBRARY_PATH
correctly). It is actually our plugin in that application which needs to
dlopen libABC.so.

Even if there's a Linux-only solution, it would be very helpful.

Thanks,
Ashu


bobroberts

2005-06-02, 3:58 pm

Ashu wrote:
> Is there a way to augment the LD_LIBRARY_PATH at runtime,
> or achieve the same effect through any other means?
> (setenv("LD_LIBRARY_PATH",...) does not work at runtime).
>
> The problem faced is this:
>
> Library libABC.so is linked against libXYZ.so, and both
> are finally kept in the same directory.
> An application knows the location of libABC.so and
> dlopen()s it (giving the full path). The call, however,
> fails because the directory containing libXYZ.so is not in
> LD_LIBRARY_PATH and so libXYZ.so can not be found.
>
> Is there a way to dlopen libABC.so although
> LD_LIBRARY_PATH is inadequate as regards the location of
> libXYZ.so?
>


I'm a little . You said that libXYZ.so is in the same directory
as libABC.so and that you open libABC.so using the fully qualified
path. Since ABC depends on XYZ, can't you just use dlopen to open XYZ
first and once it is loaded, then open libABC.so? I would think the
dependency would be satisfied then...

the dlopen(3) man page says:
External references in the library are resolved using the
libraries in that library's dependency list and any other
libraries previously opened with the RTLD_GLOBAL flag

If I've misunderstood the issue, I apologize for wasting your time...
good luck :)

-bob

Måns Rullgård

2005-06-02, 3:58 pm

"Ashu" <ashusharma@gmail.com> writes:

> Is there a way to augment the LD_LIBRARY_PATH at runtime, or achieve the
> same effect through any other means?
> (setenv("LD_LIBRARY_PATH",...) does not work at runtime).
>
> The problem faced is this:
>
> Library libABC.so is linked against libXYZ.so, and both are finally kept in
> the same directory.
> An application knows the location of libABC.so and dlopen()s it (giving the
> full path). The call, however, fails because the directory containing
> libXYZ.so is not in LD_LIBRARY_PATH and so libXYZ.so can not be found.
>
> Is there a way to dlopen libABC.so although LD_LIBRARY_PATH is inadequate as
> regards the location of libXYZ.so?
>
> The application is a third-party one, and so I cannot modify its launch
> behaviour (such as wrapping it in a script which first sets LD_LIBRARY_PATH
> correctly). It is actually our plugin in that application which needs to
> dlopen libABC.so.


If you dlopen libXYZ.so first, with the RTLD_GLOBAL flag, everything
should be fine. There may of course be reasons you don't want to do
this. If you have control over how libABC.so is built, you can add
the correct directory to its DT_RUNPATH section (see linker
documentation for how to do that).

--
Måns Rullgård
mru@inprovide.com
Ashu

2005-06-02, 3:58 pm

"Ashu" <ashusharma@gmail.com> wrote in message
news:IZxne.8577$Cz3.1029334@monger.newsread.com...
> Is there a way to augment the LD_LIBRARY_PATH at runtime, or achieve the
> same effect through any other means?
> (setenv("LD_LIBRARY_PATH",...) does not work at runtime).
>
> The problem faced is this:
>
> Library libABC.so is linked against libXYZ.so, and both are finally kept

in
> the same directory.
> An application knows the location of libABC.so and dlopen()s it (giving

the
> full path). The call, however, fails because the directory containing
> libXYZ.so is not in LD_LIBRARY_PATH and so libXYZ.so can not be found.
>
> Is there a way to dlopen libABC.so although LD_LIBRARY_PATH is inadequate

as
> regards the location of libXYZ.so?
>
> The application is a third-party one, and so I cannot modify its launch
> behaviour (such as wrapping it in a script which first sets

LD_LIBRARY_PATH
> correctly). It is actually our plugin in that application which needs to
> dlopen libABC.so.
>
> Even if there's a Linux-only solution, it would be very helpful.
>
> Thanks,
> Ashu
>
>


Thanks Måns and Bob.
Loading the dependencies first would solve the problem (in the actual case,
the number is quite high). And so would using -rpath when linking libABC.so.

Thanks,
Ashu


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com