Building python-ldap-2.4.10 on QNAP TS-210

I’m using ipkg to install some of the requirements, so check the QNAP site to see how to enable the use of this.

The python-ldap module requires a compile of some modules so you need some headers. These can be installed via ipkg:
ipkg install openldap-libs
This installs the ldap(openldap-libs_2.3.43-2_arm.ipk) and sasl (cyrus-sasl-libs_2.1.23-2_arm.ipk) libs in /opt/lib and /opt/lib/sasl2 and the header files in /opt/include and /opt/include/sasl

Download the python-ldap (Version 2.4.10 as of the time of writing this document) source from and extract to your qnap (I’m using /share/MD0_DATA/lab/)

Edit setup.cfg in the extracted directory, and change the following two lines:
library_dirs = /opt/openldap-RE24/lib /usr/lib
include_dirs = /opt/openldap-RE24/include /usr/include/sasl /usr/include

to be:
library_dirs = /opt/lib /opt/lib/sasl2
include_dirs = /opt/include /opt/include/sasl

Run : python build

I had an error:
/opt/bin/gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R -DLDAPMODULE_VERSION=2.4.10 -IModules -I/opt/include -I/opt/include/sasl -I/opt/include/python2.5 -c Modules/constants.c -o build/temp.linux-armv5tel-2.5/Modules/constants.o
Modules/constants.c: In function 'LDAPinit_constants':
Modules/constants.c:155: error: 'LDAP_OPT_DIAGNOSTIC_MESSAGE' undeclared (first use in this function)
Modules/constants.c:155: error: (Each undeclared identifier is reported only once
Modules/constants.c:155: error: for each function it appears in.)
Modules/constants.c:365: error: 'LDAP_CONTROL_RELAX' undeclared (first use in this function)
error: command '/opt/bin/gcc' failed with exit status 1

Turns out with version of python-ldap (2.4.x), OpenLDAP 2.4 client libs or newer are required. So off to find out where these are. I downloaded the ipkg’s mentioned above (openldap-libs and cyrus-sasl-libs) to try an figure how how to build the newest versions of these. Turns out the cyrus-sasl-libs haven’t been updated for a long time, the latest version is 2.1.25 and the one supplied in ipkg repo currently is 2.1.23-2. python-ldap 2.4.10 needs Cyrus SASL 2.1.x or newer so the supplied ipkg version is fine.

Building openldap-2.4.35 (without slapd) to get the libraries:
untar openldap-2.4.35.tar.gz
cd into openldap source
export PATH=/opt/bin:$PATH
./configure --prefix=/opt --disable-slapd
make depend
cd libraries

Now you need to copy them into a directory structure to build the ipkg – I found some instruction for this here (if you want to build the ipkg – if not you can just run make install from the libraries folder).

mkdir -p /share/MD0_DATA/lab/ipkg_build/openldap-libs/ipkgroot/opt/include
mkdir -p /share/MD0_DATA/lab/ipkg_build/openldap-libs/ipkgroot/opt/lib
#(from the openldap libraries folder)
cp liblber/.libs/ /share/MD0_DATA/lab/ipkg_builds/openldap-libs/ipkgroot/opt/lib/
cp libldap/.libs/ /share/MD0_DATA/lab/ipkg_builds/openldap-libs/ipkgroot/opt/lib/
cp libldap_r/.libs/ /share/MD0_DATA/lab/ipkg_builds/openldap-libs/ipkgroot/opt/lib/
#create the links
cd /share/MD0_DATA/lab/ipkg_builds/openldap-libs/ipkgroot/opt/lib
ln -s
ln -s
ln -s
ln -s
ln -s
ln -s

# now the header files
cd into the openldap source folder
cd include
cp lber.h lber_types.h ldap.h ldap_cdefs.h ldap_features.h ldap_schema.h ldap_utf8.h slapi-plugin.h /share/MD0_DATA/lab/ipkg_builds/openldap-libs/ipkgroot/opt/include/

# create the ipkg control file
cd /share/MD0_DATA/lab/ipkg_builds/openldap-libs/ipkgroot/
vi control
# add the following:
Package: openldap-libs
Architecture: arm
Priority: optional
Section: net
Version: 2.4.35
Maintainer: Your Name
Description: Open Lightweight Directory Access Protocol
Depends: openssl, libdb, gdbm, cyrus-sasl-libs, psmisc

# save and quit the file

# now you need to compile the python modules:
cd /share/MD0_DATA/lab/ipkg_builds/openldap-libs

# now create the ipkg

# make sure the permissions are correct:
# find all directories and make them readable by everyone
find ipkgroot/ -type d -exec chmod 755 '{}' \;
# find all files and make them readable
find ipkgroot/ -type f -exec chmod og+r '{}' \; ipkgroot

You should now have a file named ‘openldap-libs_2.4.35_arm.ipk’ in /share/MD0_DATA/lab/ipkg_builds/openldap-libs
You can install this using ipkg:
ipkg install openldap-libs_2.4.35_arm.ipk
I’ve also uploaded this ipkg to

So now, back to building python-ldap. Change back into the python-ldap source directory and run ‘python build’ and this time it built, Yay!

Once the build is complete, you can either just run python install and you are done, or use create an ipkg.

    Creating the python-ldap ipkg

mkdir -p /share/MD0_DATA/lab/ipkg_builds/python-ldap/ipkgroot/opt/lib/python2.5/site-packages
cd /share/MD0_DATA/lab/ipkg_builds/python-ldap
cp -a python-ldap-2.4.10/build/lib.linux-armv5tel-2.5/* ipkgroot/opt/lib/python2.5/site-packages/
# now get the demos
mkdir -p ipkgroot/opt/share/doc/python-ldap-2.4.10
cp -a python-ldap-2.4.10/Demo ipkgroot/opt/share/doc/python-ldap-2.4.10/
# get the licence, readme and todo
cp -a python-ldap-2.4.10/LICENCE python-ldap-2.4.10/README python-ldap-2.4.10/TODO ipkgroot/opt/share/doc/python-ldap-2.4.10/
# finally the egg file
cp -a python-ldap-2.4.10/Lib/python_ldap.egg-info/PKG-INFO ipkgroot/opt/lib/python2.5/site-packages/python-ldap-2.4.10-py2.5.egg-info

# start python from the command line and enter:

import compileall
compileall.compile_dir('site-packages', force=True)

# This will go through the site-packages directory recursively and compile all the .py files.

# create the control file
mkdir ipkgroot/CONTROL
vi ipkgroot/CONTROL/control

# add the following to that file
Package: py25-python-ldap
Architecture: arm
Priority: optional
Section: misc
Version: 2.4.10
Maintainer: Your Name
Description: Provides an object-oriented API to access LDAP directory servers from Python programs. Mainly it wraps the OpenLDAP 2.x libs for that purpose. Additionally the package contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAPURLs, LDAPv3 schema, LDAPv3 extended operations and controls, etc.).
Depends: python25

# write and quit the file
# now create the ipkg
# make sure the permissions are correct:
# find all directories and make them readable by everyone
find ipkgroot/ -type d -exec chmod 755 '{}' \;
# find all files and make them readable
find ipkgroot/ -type f -exec chmod og+r '{}' \; ipkgroot

You will now have py25-python-ldap_2.4.10_arm.ipk in you current directory which you can do whatever you like with.
I’ve also created packages for python 2.6 and 2.7, they are all available to download from here: