How can I find the full file path given a library name like libfoo.so.1?

c, linker, linux

Solution

Use ldconfig which is the tool that manages link space.

The `-p` flag lets you browse all available linkable libraries.

Problem

Without implementing a linker or using `ldd`, how can I find the full path to a library? Is there a standard library available for that on Linux? (POSIX maybe?) Using `ldd` and `grep` on a file that is knowingly using `libGL.so.1`, it looks like: ``` $ ldd /usr/bin/glxinfo | grep libGL libGL.so.1 => /usr/lib/libGL.so.1 (0x00007f34ff796000) ``` Given a library name like `libGL.so.1`, how can I find the full path `/usr/lib/libGL.so.1`?. Preferably accepting an option for finding 32-bit and 64-bit libraries. If no library does that, does a program exist to do this? Something like `find-library-path libGL.so.1`. The `locate libGL.so.1` command does not count. I don't want to actually load the library using `dlopen` or something if it executes code from that library.

Original source