[problem]
Getting an error about not being able to find libraries (file not found), when starting up a binary – such as httpd.
[/problem]
[solution]
You need to identify the shared libraries required by your binary. Ordinarly we use the ldd command for this and amended LD_LIBRARY_PATH to find the libs – see example below.
You might also want to get the shared libs of a running process – with pldd or need to dig into a lib/binary.
[/solution]
[example]
# find dependencies for a binary
 % ldd /usr/bin/httpd
 libpng.so.2 =>   /usr/local/lib/libpng.so.2
 libcrypt_i.so.1 =>       /usr/lib/libcrypt_i.so.1
 libresolv.so.2 =>        /usr/lib/libresolv.so.2
 …
 
# demo of how ldd walks the values in LD_LIBRARY_PATH
 % unset LD_LIBRARY_PATH
% ldd /usr/bin/httpd
 libpng.so.2 =>   (file not found)
 libcrypt_i.so.1 =>       /usr/lib/libcrypt_i.so.1
 libresolv.so.2 =>        /usr/lib/libresolv.so.2
 …
 
# find files installed via a package on Solaris
 % grep libpng.so.2 /var/sadm/install/contents  | head -1
 /usr/sf/lib/libpng.so=libpng.so.2 s none SUNWpng
 
Another way to see which libraries are being picked up, i.e. if a binary works on one system and not another:
 % truss -t'open' -f date
 21667:  open("/var/ld/ld.config", O_RDONLY)             Err#2 ENOENT
 21667:  open("/usr/lib/libc.so.1", O_RDONLY)            = 3
 21667:  open("/usr/lib/libdl.so.1", O_RDONLY)           = 3
 ...
 
Getting the dependent shared libraries of a running process (especially where vars might have changed since startup):
 % pldd 24832
 24832:  /usr/bin/httpd
 /usr/local/lib/libpng.so.2.1.0.5
 /usr/lib/libcrypt_i.so.1
 /usr/lib/libresolv.so.2
 ...
 
Seeing more detail via the headers within an object file (use objdump on linux):
 % elfdump /usr/bin/httpd | grep NEEDED
 [0]  NEEDED           0x15755           libpng.so.2
 [1]  NEEDED           0x15761           libcrypt_i.so.1
 [2]  NEEDED           0x15771           libresolv.so.2
 ...
 
See configure parameters passed to a binary during compilation (can also be useful for getting a usage out a binary, that does not appear by default or with –h, etc):
[/example]
[reference]
[/reference]
[tags][/tags]
If you have found my website useful, please consider buying me a coffee below 😉