Thread: Fix linking of OpenLDAP libraries

Fix linking of OpenLDAP libraries

From
"Albe Laurenz"
Date:
I have realized that my modifications in configure.in and
src/interfaces/libpq/Makefile to link libpq against
OpenLDAP are buggy.

Here is a proposed patch to fix it.

I write this to pgsql-hackers too because I want to share
the difficulty I'm facing - maybe somebody has a better
idea.

To handle thread safety, OpenLDAP comes with a second
library libldap_r. The thread safe API is identical to
the normal API, the difference is that you must link
against libldap_r instead of libldap to get thead safety.

These are my problems:
- While libpq should be thread safe when ./configured with
  --enable_thread_safety, the backend should be linked
  against the normal libldap.
- At least on RedHat Linux, you need to link against the
  pthread library too if you want to link against libldap_r,
  because the latter has unresolved dependencies.

My solution:
- If thread safety is not desired, I link against libldap.
  No problem.
- If thread safety is desired, I first try to link against
  libldap_r without the thread libraries, and only if that
  fails add the thread libraries to LIBS.
- I tweak src/backend/Makefile so that it strips libldap_r
  and the thread libs from LIBS and replace it with
  libldap if necessary.

That means that if --enable_thread_safety and --with-ldap
is both specified, all executables except 'postgres' will
be linked against libldap_r (and the thread libs, if
necessary).

I tested my patch on RedHat Enterprise Linux 3 and AIX 5.3.

The behaviour for Windows (use the native WLDAP32.DLL)
is unchanged.

Yours,
Laurenz Albe

Attachment

Re: Fix linking of OpenLDAP libraries

From
Tom Lane
Date:
"Albe Laurenz" <all@adv.magwien.gv.at> writes:

>   # The backend doesn't need everything that's in LIBS, however
> ! LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses -lldap_r $(PTHREAD_LIBS), $(LIBS))

This seems pretty risky.  What if PTHREAD_LIBS contains -L switches?
They'd get removed even if needed for other libraries.

It would probably be safer not to put LDAP into LIBS at all, but invent
two new macros for configure to set, say LDAP_LIBS and LDAP_LIBS_R,
and add these to the link lines in the backend and libpq respectively.

            regards, tom lane

Re: Fix linking of OpenLDAP libraries

From
"Albe Laurenz"
Date:
Tom Lane wrote on September 04, 2006:
> "Albe Laurenz" <all@adv.magwien.gv.at> writes:
>
>>   # The backend doesn't need everything that's in LIBS, however
>> ! LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses
-lcurses -lldap_r $(PTHREAD_LIBS), $(LIBS))
>
> This seems pretty risky.  What if PTHREAD_LIBS contains -L switches?
> They'd get removed even if needed for other libraries.
>
> It would probably be safer not to put LDAP into LIBS at all, but
invent
> two new macros for configure to set, say LDAP_LIBS and LDAP_LIBS_R,
> and add these to the link lines in the backend and libpq respectively.

That seems like a good idea.
I'll try to work it out and resubmit the fix.

Yours,
Laurenz Albe