Resolve GCC error when installing python-ldap on Redhat Enterprise Server

eikonomega picture eikonomega · Sep 12, 2013 · Viewed 6.9k times · Source

Python-LDAP + Redhat = Gnashing of Teeth

Recently, I spent a few hours tearing my hair (or what's left of it) out attempting to install python-ldap (via pip) onto a Redhat Enterprise server.

Here's the error message that I would get (look familiar?):

Modules/constants.c:365: error: ‘LDAP_CONTROL_RELAX’ undeclared (first use in this function) error: command 'gcc' failed with exit status 1

If only there was someone out there that could help me!

Answer

eikonomega picture eikonomega · Sep 12, 2013

But wait! I can help you, because I figured it out after a copious amount of cursing!

Step 1: Verify Prerequisites are Installed

According to the docs you must have OpenLDAP libraries installed on your system. At the time that I'm writing the version requirement for the libraries was >= 2.4.11

To see whether or not you have such libraries installed on your system, run this command: yum list installed openldap*

Here is the output from my system as an example of what you might see:

PACKAGE                                                         VERSION
openldap24-libs.i386                                            2.4.23-5.el5                                     
openldap24-libs.x86_64                                          2.4.23-5.el5                                     
openldap24-libs-devel.i386                                      2.4.23-5.el5                                     
openldap24-libs-devel.x86_64                                    2.4.23-5.el5

So, in my case, I already had the libraries installed. If you don't just run:

sudo yum install openldap24-libs-devel  
sudo yum install openldap24-libs

Step 2: Where were those Packages Installed?

If the packages are already installed and pip is still failing, then perhaps the setup.cfg script is looking in the wrong place for the required library files. So, let's find out where they exist on our system.

Do this:

rpm -ql openldap24-libs
rpm -ql openldap24-libs-devel

And you should get something like this (I've abbreviated this so we can see the directories involved more easily).

rpm -ql openldap24-libs
/usr/lib64/...
/usr/lib/...

rpm -ql openldap24-libs-devel
/usr/include/openldap24/...
/usr/lib/openldap24/...
/usr/lib64/openldap24/...

Step 3: Check Pip's setup.cfg file for python-ldap

  • When a pip install command fails, it leaves behind a build directory inside of the python interpreter's base directory (same place that you'll find /bin, /include, /lib, and /man.
  • Inside the build directory you should find `python-ldap/setup.cfg'.
  • Open the file inside your favorite editor.

You should see this at the top of the file:

[_ldap]
library_dirs = /opt/openldap-RE24/lib /usr/lib
include_dirs = /opt/openldap-RE24/include /usr/include/sasl /usr/include

Obviously, this is wrong. Append the directories you discovered in step 2 in front of the directories currently listed so that you end up with something like:

[_ldap]
library_dirs = /usr/lib64/openldap24 /usr/lib/openldap24 /usr/lib64 /opt/openldap-RE24/lib /usr/lib
include_dirs = /usr/include/openldap24 /opt/openldap-RE24/include /usr/include/sasl /usr/include

Step 4: Re-Run Installation & PROFIT!

After saving the file, you can simply run pip install python-ldap again. The installation process will look at your update setup.cfg and should install without any further issues.