Linker search paths

As part of my job as a systems administrator, I occassionally need to develop scripts to start applications at system bootstrap. Periodically while developing these scripts I will encounter an application that relies on libraries in obscure locations. To allow my scripts to work with these applications, I typically need to set LD_LIBRARY_PATH so the runtime linker can locate the libraries needed to make the application work ( I say typically since setrpath can be used on occassion ). Since the Solaris linker searches for libraries in the following order:

1. Check for libraries by traversing the directories in the LD_LIBRARY_PATH environment variable

2. Check for libraries by traversing the directories in the executables’s RPATH

3. Check for libraries by traversing /lib and /usr/lib

It is usually unnecessary to explicitly add /lib and /usr/lib to the search path. To see this first hand, the ldd utility can be invoked with the “-s” (display search path) option and an executable to process:

$ ldd -s slapd

   find object=libdb-4.3.so; required by /usr/local/openldap-2.2.26/libexec/slapd
    search path=/lib:/usr/lib  (default)
    trying path=/lib/libdb-4.3.so
    trying path=/usr/lib/libdb-4.3.so
        libdb-4.3.so =>  (file not found)

   find object=libsasl.so.1; required by /usr/local/openldap-2.2.26/libexec/slapd
    search path=/lib:/usr/lib  (default)
    trying path=/lib/libsasl.so.1
    trying path=/usr/lib/libsasl.so.1
        libsasl.so.1 =>  /usr/lib/libsasl.so.1
  
   [ ..... ]

Each stanza contains the name of a library that the executable requires, along with the directories that are searched to locate the library. This is some useful stuff!

2 thoughts on “Linker search paths”

  1. You can also use crle on solaris 8 and above (similar to linux ldconfig) to tell executables where to find directories that contain libraries. I generally tend to think of LD_LIBRARY_PATH as only a temporary solution, there are too many ways it which it can be subverted for using permantly.

  2. crle is definitely the way to go. The reasons to use LD_LIBRARY_PATH should be few and far between!

Leave a Reply

Your email address will not be published. Required fields are marked *