Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers 3

up vote 4 down vote accepted

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}'
share|improve this answer
add comment

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 ]
share|improve this answer
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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