[ale] How do I force a specific version of a shared library to be loaded/used?

JK jknapka at kneuro.net
Wed Jun 14 15:00:45 EDT 2006


Keith Hopkins wrote:

>Jim wrote:
>  
>
>>Jim wrote:
>>    
>>
>>>I have two versions of mysqlclient installed on the system, 
>>>mysqlclient.so.14 and mysqlclient.so.12.  I'm compiling/running a 
>>>program that needs to be linked to 14, but it's defaulting to 12.  How 
>>>do I encourage it to link to 14?  Google wasn't much help.
>>>
>>>Thanks,
>>>Jim.
>>>_______________________________________________
>>>Ale mailing list
>>>Ale at ale.org
>>>http://www.ale.org/mailman/listinfo/ale
>>>
>>>
>>>
>>>  
>>>      
>>>
>>Never mind.  I didn't have libmysqlclient14-dev installed.  Sorry for 
>>the wasted bandwidth.
>>
>>Jim.
>>_______________________________________________
>>Ale mailing list
>>Ale at ale.org
>>http://www.ale.org/mailman/listinfo/ale
>>
>>!DSPAM:44902e87158561988011713!
>>
>>    
>>
>
>Interesting question, which I just bothered to look up, so I'll tell you anyway:
>
>man ld.so
>
> The shared libraries needed by the program are searched for in various places:
>
>       o      (ELF only) Using the DT_RPATH dynamic section attribute of the binary if present and DT_RUNPATH attribute does not exist.   Use
>              of DT_RPATH is deprecated.
>
>       o      Using  the  environment variable LD_LIBRARY_PATH.  Except if the executable is a set-user-ID/set-group-ID binary, in which case
>              it is ignored.
>
>       o      (ELF only) Using the DT_RUNPATH dynamic section attribute of the binary if present.
>
>       o      From the cache file /etc/ld.so.cache which contains a compiled list of candidate libraries previously found  in  the  augmented
>              library  path.  If,  however,  the binary was linked with -z nodeflib linker option, libraries in the default library paths are
>              skipped.
>
>       o      In the default path /lib, and then /usr/lib.  If the binary was linked with -z nodeflib linker option, this step is skipped.
>
>
>Setting LD_LIBRARY_PATH is the method I see used most often.
>  
>

But LD_LIBRARY_PATH will not necessarily cause a specific
*version* of a lib to be loaded. It just tells ld.so which
directories to look in to find libs. If you put the version
you want loaded in a particular dir and then add that dir
to the beginning of LD_LIBRARY_PATH, that will probably
do what you want. However, there's an easier way: add the
exact library you want to use to LD_PRELOAD.  The contents
of that environment variable is a list of .so files to be
loaded before anything else; symbols in those libraries will
resolve first, so additional libs will only be loaded in
order to resolve symbols not found in the LD_PRELOAD library
list. (This is all described in "man ld.so", in the
ENVIRONMENT section.)

-- JK




More information about the Ale mailing list