Solved 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? TIA Michael PS: I link: -ldap -lber -ssl -crypto -cygwin
-
Hi,
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 $MAKE cd ../libldap $MAKE libldap.la sed -E 's/\/cygdrive\/c/C:/' libldap.la > xx ; mv xx libldap.la cd ../libldap_r $MAKE libldap_r.la sed -E 's/\/cygdrive\/c/C:/' libldap_r.la > xx ; mv xx libldap_r.la cd ../.. $MAKE $MAKE install
-
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)Regards
Michael -
Good to know, thanks for the details.
Happy hacking !
-
@micky can you tell for ubuntu linux platform?
-
Install the libldap2-dev package.
-
I got connection with ldap / active directory. Now i want to check and retrieve the particular user's data.
lc->bind("cn=admin,dc=domain,dc=org", "pass",cons); bool result = lc->compare("cn=admin,dc=domain,dc=org", LDAPAttribute("cn","admin")); LDAPAttributeList* attrs=new LDAPAttributeList(); std::cout << "Attribute List ID: " << attrs << std::endl; LDAPSearchResults* entries = lc->search("DC=doamin,DC=org", LDAPConnection::SEARCH_ONE);
if (entries != 0){ LDAPEntry* entry = entries->getNext(); if(entry != 0){ std::cout << *(entry) << std::endl; } while(entry){ try{ entry = entries->getNext(); if(entry != 0){ std::cout << *(entry) << std::endl; } delete entry; }catch(LDAPReferralException e){ std::cout << "Caught Referral" << std::endl; } } }
Here it returns user groups and lots od cn, and dc, users list and etc.
But i want to check one particular user is exist or not in from this output and if exist i need that user's data.Plz help. Thanks in advance.
-
That's something you should ask the library developers.