library paths, ldconfig & crle

Fixing up the shared library path is a frequent necessity. What lots forget is Solaris has an equivalent command to Linux's ldconfig for modifying the default system wide search path, named crle. The shared library path basically tells the operating system where to look for shared libraries required by programs to run. It is especially important when you've installed multiple versions of libraries and need a way to guarantee the right libraries are used by the right programs. For example, we installed a pre-compiled version of the Apache web server on a Sparc/Solaris8 system which was linked to a specific Openssl library version. Since there were already earlier versions of the Openssl libraries on the system we had to modify the shared library path based on which user was executing what to ensure proper linking.

Set the LD_LIBRARY_PATH variable:

% export LD_LIBRARY_PATH=/opt/usr/local/lib:/opt/usr/local/libexec:/opt/usr/local/pgsql/lib:/opt/usr/local/pgsql/libexec:/opt/usr/local/ssl/lib (removed several dirs to keep this short)

To verify an executable can find and link to the right shared libraries, use ldd:

% user@server /opt/usr/local/sbin> ldd lighttpd (ldd -s is more powerful)
libpcre.so.0 => /opt/usr/local/lib/libpcre.so.0
libdl.so.1 => /usr/lib/libdl.so.1
libsendfile.so.1 => /usr/lib/libsendfile.so.1
libresolv.so.2 => /usr/lib/libresolv.so.2
libnsl.so.1 => /usr/lib/libnsl.so.1
libsocket.so.1 => /usr/lib/libsocket.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /opt/usr/local/lib/libgcc_s.so.1
libmp.so.2 => /usr/lib/libmp.so.2
/usr/platform/SUNW,Ultra-80/lib/libc_psr.so.1

You can use Linux's ldconfig command and Solaris' crle command to create default system wide search paths and use LD_LIBRARY_PATH to override the path when necessary.

Below is a chart describing the correct shared path variable names for different OSes:

OS

32bit

64bit (if different from 32)

Delimiter

AIX

LIBPATH


: (colon)

HP-UX

SHLIB_PATH

LD_LIBRARY_PATH

: (colon)

Solaris

LD_LIBRARY_PATH

LD_LIBRARY_PATH_64

: (colon)

Linux

LD_LIBRARY_PATH


: (colon)

Tru64

LD_LIBRARY_PATH


: (colon)

SCO

LD_LIBRARY_PATH


: (colon)

Unixware

LD_LIBRARY_PATH


: (colon)

Windows

PATH


; (semicolon

Posted by tate 19/03/2006 at 03h31