9

I am looking for a utility that would behave in the same way as which, but to look up shared libraries (*.so) in the directories defined in $LD_LIBRARY_PATH?

5

If you have an executable and you want to see where it's picking up libraries, run

ldd /path/to/executable

This will account for libraries on the default search path as well as libraries in this executable's rpath if any.

On Linux, paths to system libraries are cached for efficiency. /sbin/ldconfig -p displays the contents of the cache (it's stored in /etc/ld.so.cache). Here's a script that shows the location(s) of a library:

#!/bin/sh
if [ -n "$LD_LIBRARY_PATH" ]; then
  set -f
  IFS=:
  for d in $LD_LIBRARY_PATH; do
    if [ -e "$d/$1" ]; then echo "$1"; fi
  done
fi
/sbin/ldconfig -p |
awk -v needle="$1" '$1 == needle {sub(/.* => /, ""); print}'
5

If your libraries are properly cached you should be abled to find it via:

ldconfig -p|grep "yourlibrary"

If you search for a library that came with your distribution you could use the distribution means of searching for files within packages.

  • zypper wp "*/library.so" (SLES and OpenSuSE)
  • yum provides "*/library.so" (RedHat and its clones)

This will also output rpms that are not installed, but are part of your active installation sources.

3

If you are looking for a utility that will work like gcc's -lLIBNAME flag, which looks for a file called libLIBNAME.so then you could probably use a little script that does something like this:

#!/bin/sh
ldpath="${LD_LIBRARY_PATH:-$(</etc/ld.so.conf)}"
notfound=1
for libdir in ${ldpath//:/ }; do
        (test -f "$libdir/lib${1}.so" && echo "$_") && notfound=0
done
[ "$notfound" -eq 0 ]
  • 1
    Thanks for the script but I'm really wondering if there's a "standard" utility for this. – rahmu Oct 6 '11 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.