tags:

views:

34

answers:

3

I have a shared object ( libxyz.so ). Given LD_LIBRARY_PATH, how can find the exact location of this shared object? If i had a binary that depends on this lib, i would have used ldd on that.

Here is the reason why i ask: I have a cgi script which works when using LD_LIBRARY_PATH set to say VALUE1. It does not work when the path is set to VALUE2. I would like to find the exact location of the library as specified by the path in VALUE1 ( Note that VALUE1 has almost 20+ different locations )

Platform: Linux

+1  A: 

Put this in a file:

#!/bin/bash
IFS=:

for p in ${LD_LIBRARY_PATH}; do
    if [ -e ${p}/libxyz.so ]; then
        echo ${p}
    fi
done

and run it.

R Samuel Klatchko
Thanks for the response. I was just wondering if there is an existing linux tool to this. Also, i noticed some files within the lib folders which have path names to other lib folders - so this also needs to recursively look at those directories
CuriousDawg
oh btw, this does not work without first splitting the path using : delimiter
CuriousDawg
@CuriousDawg - did you try the example exactly as I wrote it? `IFS=:` tells bash to treat : as the delimiter (or field separator in bash parlance).
R Samuel Klatchko
A: 

put a sleep(30); in your cgi, launch it from a browser, then look into /proc/$(pidof mycgi)/maps for actual libs used by your program.

ggiroux
A: 

You can also use ldd. To do this, you would:

  1. Set LD_LIBRARY_PATH to the value when it works (i.e. export LD_LIBRARY_PATH=VALUE1)
  2. Run ldd /path/to/prog | grep libxyz.so
R Samuel Klatchko
Yes i can do that, but this is a cgi script and ldd does not work on scripts
CuriousDawg
@CuriousDawg - if it's a script, run `ldd` on the interpreter (i.e. the program after `#!`)
R Samuel Klatchko