(Answer) (Category) OpenLDAP Faq-O-Matic : (Category) OpenLDAP Developer's FAQ : (Category) Running Programs : (Answer) How do I get my program to load a shared library?
You get an error when trying to run slapd or ldapsearch, such as
        cannot load shared library libsasl.so.7
what to do?
This error occurs because the library is not in one of the standard system directories and you have not provided the information necessary to give the run-time loader (the program which assembles all the required shared libraries together into an executable before it can be started).
There are several ways to do this. Most systems that support shared libraries will look at the environment variable LD_LIBRARY_PATH. It is expected to contain a list of colon-separated directories. So if, for example, the shared library for Sleepycat's db3.1 was not found when running slapd, doing
        LD_LIBRARY_PATH=/usr/local/BerkeleyDB.3.1/lib
could resolve the problem immediately. You should take care in your environment not to simply clobber LD_LIBRARY_PATH. If one is already there, then your system administrator (or you) has it there for a reason and you should append to it.
Not all operating systems support LD_LIBRARY_PATH. HPUX and IBM AIX are notable exceptions. Refer to the manpage for 'rld' or 'ld' if you are using one of these.
In practice it is tiresome to keep making sure that LD_LIBRARY_PATH is set for every program you might want to run. There are two other basic ways around this. One is to alter the system-wide default list of directories that are searched via some tool such as 'ldconfig'. Again, 'man ld' and/or 'man rld' should help navigate you to the details of your particular operating system.
The second way, which is available on most modern operating systems that support shared libraries, is that a list of directories to be searched for resolving shared library references at run-time can be stored directly into executables, and sometimes into shared libraries as well. This means you don't have to muck with the system-wide defaults, which you may not have access to or want to change. There are options to the 'ld' command, often either -R or -rpath followed by a directory pathname.
For example, if you set
        LDFLAGS=-L/server/local/BerkeleyDB/lib
to find the Sleepycat DB library (of course, you also set CPPFLAGS so it would find db.h) you can change it to
        LDFLAGS="-L/server/local/BerkeleyDB/lib -R/server/local/BerkeleyDB/lib"
This instructs ld to not only to search /server/local/BerkeleyDB/lib when searching for libraries designated with -l flags, but also to add (via -R) /server/local/BerkeleyDB/lib to the run-time directory list. You might think this should be automatic, but it is not. Again, the exact flags will vary. For example, on OSF, I use -rpath instead of -R. But the basic idea is the same, and again studying 'man ld' will lead you in the right direction.
By the way, you should always point to the directory that contains the installed shared library, not to the source tree where you built it.
kunkee@neosoft.com
[Append to This Answer]
This document is: http://www.openldap.org/faq/index.cgi?file=511
[Search] [Appearance]
This is a Faq-O-Matic 2.719.
© Copyright 2004, OpenLDAP Foundation, info@OpenLDAP.org