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?

- 20,023
3 Answers
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.

- 18,492
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}'

- 829,060
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 ]

- 5,517
- 2
- 35
- 43