Build OpenLDAP 2.3.x from sources on Ubuntu

It happened so that I needed to build a particular version of OpenLDAP on Ubuntu and use that instead of the one in Ubuntu’s repository. Here is a quick guide as to how it worked for me:

1. Get BDB 4.3 sources from Oracle’s site(link)

2. Compile BDB and install it:

tar –xvzf db-4.3.29.tar.gz
cd db-4.3.29/build_unix
./configure --prefix=/usr/local/bdb43
sudo make install

3. Get OpenLDAP source(ftp link)
4. Compile and install it:

tar xzvf openldap-2.3.35.tgz
cd openldap
export CPPFLAGS="-I/usr/local/bdb43/include -D_GNU_SOURCE" 
export LDFLAGS="-L/usr/local/lib -L/usr/local/bdb43/lib -R/usr/local/bdb43lib" 
export LD_LIBRARY_PATH="/usr/local/bdb43/lib"
./configure --prefix=/usr/local/openldap

If you’re installing version 2.3.x or anything before 2.4.15 you will need to manually patch OpenLDAP otherwise you’ll get this error:
../../include/ldap_pvt_thread.h:64: error: missing binary operator before token “(“
Patch file is available in this bug report
Or already patched file for OpenLDAP version 2.3.35 you can download here

If you’re installing anything >= 2.4.15, you can skip the patch.

Once patch is applied just run:

make depend
make test  #this will take a while to run 
make install

Common Errors:
configure: error: Berkeley DB version mismatch
Solution: Most likely you didn’t LDFLAGS and LD_LIBRARY_PATH as noted above

getpeereid.c:52: error: storage size of ‘peercred’ isn’t known
You need to include -D_GNU_SOURCE flag, to avoid incompatibility with glibc

../../include/ldap_pvt_thread.h:64: error: missing binary operator before token “(“
Solution: Apply patch as noted above

error while loading shared libraries: cannot open shared object file: No such file or directory
Solution: Add libdb-4.3 to shared libs cache:

sudo echo "/usr/local/bdb43/lib" > /etc/
lddconfig -v