gccopenldappython-ldap

python-ldap 3.4 installation fails on alpine images


When trying to install the latest python-ldap version 3.4 on an apline docker image (I use python:3.9-alpine as my base image) the build of python-ldap fails with:

...
/usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lldap_r
    collect2: error: ld returned 1 exit status
    error: command '/usr/bin/gcc' failed with exit code 
...

Installed dependencies:

apk add --no-cache --virtual .build-deps musl-dev gcc postgresql-dev openldap-dev libffi-dev

Also tried with build-base etc. without success.

Would highly appreciate any ideas :)


Solution

  • There are issues with the python-ldap package when linking against OpenLDAP 2.5+. The issues are acknowledged by the devs in https://github.com/python-ldap/python-ldap/issues/432 and https://github.com/python-ldap/python-ldap/issues/445.

    Tested workaround is the one described in the first issue:

    As a workaround create the file /usr/lib64/libldap_r.so with content INPUT ( libldap.so ). The approach works on all systems that use a GNU ld-compatible linker.

     # cat > /usr/lib64/libldap_r.so << EOF
     INPUT ( libldap.so )
     EOF
    

    You can also use it in a simpler way (in Dockerfiles, for example):

    echo -n "INPUT ( libldap.so )" > /usr/lib/libldap_r.so