In some cases, you might want to know which directory my program links to.
There are three ways to deal with this easily.
1. LDD command
$ LDD App
2. Static Lookup
$ locate Lib_name
3. Dynamic implementation
$ strace App 2>&1 | grep lib_name
Let me give you an example.
Ubuntu's 64-bit LS is linked to the Libselinux.so.1 library.
So we're going to find out where this library is.
1. ldd
$ ldd/bin/ls
Libselinux.so.1 =>/lib64/libselinux.so.1 (0x00007f97dd5a9000)
In addition, if LDD finds a library that is not found, you can use Ldd-r to print out specific symbols.
Like what:
# ldd-r/test.
Linux-vdso.so.1 => (0x00007fff8a32b000)
Libfoo.so => not found
Libc.so.6 =>/lib64/libc.so.6 (0x00007fef5bfa9000)
/lib64/ld-linux-x86-64.so.2 (0x00007fef5c352000)
Undefined Symbol:foo (./test)
2. Static Lookup
$ locate Libselinux.so.1
/lib/i386-linux-gnu/libselinux.so.1
/lib/x86_64-linux-gnu/libselinux.so.1
We can see that there are two positions, one is the bit and the other is the bit.
Because we know that LS is 64 bits, the corresponding library should be:/lib/x86_64-linux-gnu/libselinux.so.1
3. Dynamic implementation
$ strace ls 2>&1 | grep libselinux.so.1
Open ("/lib/x86_64-linux-gnu/libselinux.so.1", o_rdonly| O_CLOEXEC) = 3
Through open this system call we know the use is:/lib/x86_64-linux-gnu/libselinux.so.1