How can I use openLDAP from a Qt-Application under Windows

  • Hello,
    I'm trying to access an openLDAP DB from Qt. Under Linux no problem at all. Under Windows I compiled openLDAP-2.4.44 under cygwin without errors but when I link the resulting libldap and liblber to my program I get:

    C:/Qt/Qt5.6.1/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-atonexit.o):atonexit.c:(.text+0xc0): multiple definition of `atexit'
    C:/cygwin/lib/libcygwin.a(atexit.o):/usr/src/debug/cygwin-2.5.2-1/winsup/cygwin/lib/atexit.c:19: first defined here
    Can anybody help?
    PS: I link: -ldap -lber -ssl -crypto -cygwin

  • Lifetime Qt Champion


    I haven't done it but AFAIK, you shouldn't mix Cygwin and MinGW. You'll have to build openLDAP directly with MinGW or build Qt for Cygwin.

  • Hi ,

    I finally found the solution. It's true, you can't mix Qt with cygwin. You have to compile openLDAP with MinGW which is a bit tricky. For those who are interested : Here is my batch (ugly hack ;-) ) to compile openLDAP:

    export PATH=/cygdrive/c/MinGW/bin:/cygdrive/c/cygwin/bin
    export MAKE=C:/MinGW/bin/mingw32-make.exe
    export CC=C:/MinGW/bin/mingw32-gcc.exe
    export SED=C:/cygwin/usr/bin/sed.exe
    export CPPFLAGS="-IC:/MinGW/include -IC:/cygwin/usr/local/include"
    export LDFLAGS="-LC:/Qt/Qt5.6.1/Tools/mingw492_32/opt/lib/ -lssl -lcrypto -LC:/cygwin/usr/local/lib -lregex -LC:/MinGW/lib -lws2_32"
    export LIBS="C:/Windows/System32/wsock32.dll"
    rm -rf openldap-2.4.44
    tar xvzf openldap-2.4.44.tgz  
    cd openldap-2.4.44
    ./configure --prefix=C:/openLDAP --disable-slapd --disable-debug --with-yielding_select=no --with-cyrus-sasl=no
    sed -E '/undef HAVE_WINSOCK_H/a#define HAVE_WINSOCK_H 1' include/portable.h > xx ; mv xx include/portable.h
    sed -E '/undef HAVE_WINSOCK\s/a#define HAVE_WINSOCK 1' include/portable.h > xx ; mv xx include/portable.h
    sed -E 's/\/cygdrive\/c/C:/' config.status > xx ; mv xx config.status
    /usr/bin/find . -name Makefile -exec sh -c "sed -E 's/^LN_S\\s*=.*/LN_S = cp/' {} > xx" \; -exec mv xx {} \;
    /usr/bin/find . -name Makefile -exec sh -c "sed -E 's/\/cygdrive\/c/C:/' {} > xx" \; -exec mv xx {} \;
    $MAKE depend
    cd libraries/liblber
    cd ../libldap
    sed -E 's/\/cygdrive\/c/C:/' > xx ; mv xx
    cd ../libldap_r
    sed -E 's/\/cygdrive\/c/C:/' > xx ; mv xx
    cd ../..
    $MAKE install

  • Lifetime Qt Champion

    Out of curiosity, why do you have cygdrive in your PATH and MAKE ? the MinGW provided by Qt should contain what you need, doesn't it ?

  • Because the sed provided with MinGW didn't work correctly. I don't know any more the exact details.
    As mentioned before: It's a hack that works for me. Perhaps I optimize it in the future (and integrate openLDAP into MXE)


  • Lifetime Qt Champion

    Good to know, thanks for the details.

    Happy hacking !

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.