Re: [PATCHES] Fix linking of OpenLDAP libraries - Mailing list pgsql-hackers

From Albe Laurenz
Subject Re: [PATCHES] Fix linking of OpenLDAP libraries
Date
Msg-id 52EF20B2E3209443BC37736D00C3C1380A4DD00D@EXADV1.host.magwien.gv.at
Whole thread Raw
Responses Re: [PATCHES] Fix linking of OpenLDAP libraries  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane wrote:
>> It builds fine on AIX 5.3 as long as you tell it to link with
>> libpq.so. Static builds against libpq.a will fail.
>
> Hm.  We have been assuming that AIX's problem is that dynamic
libraries
> don't remember their dependencies properly, but maybe the real issue
is
> that it prefers static over dynamic libraries?  If so, what we ought
to
> be doing is adding the prefer-dynamic-libraries switch to the default
> LDFLAGS on that platform.

AIX shared libraries know their dependencies well, and you don't
have to specify them again when linking against the library.

Let me expand a little on some of the peculiarities of
shared libraries on AIX:

- A normal AIX shared library is called libXX.a It is an 'ar' archive that contains the shared object(s).
- In static linking mode, the shared object will be included in the executable. In dynamic linking mode (the default)
onlya reference to the shared object is included. 
- AIX can also link against shared objects called libXX.so (like other UNIXen).
- When it resolves a -lXX flag, the linker searches the -L list for libXX.a and libXX.so. It prefers libXX.a over
libXX.sounless invoked with the flag -brtl. 

So the linker does not prefer static over dynamic libraries,
it just perfers libXX.a over libXX.so.

In our case, we have libpq.a and libpq.so in the same directory,
so unless you link with -brtl you will get a static link
(because libpq.a is a static library).

To illustrate, let me include the output of 'ldd psql' for
a dynamically linked PostgreSQL:

8.2/bin/psql needs:        /postgres/8.2/lib/libpq.so        /usr/lib/libpthread.a(shr_xpg5_64.o)
/usr/lib/libc.a(shr_64.o)       /usr/local/lib/libldap_r.a(libldap_r-2.3.so.0)        /unix
/usr/lib/libcrypt.a(shr_64.o)       /usr/lib/libs.a(shr_64.o) 

See
http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/c
om.ibm.aix.cmds/doc/aixcmds3/ld.htm

Should -brtl be added to src/template/aix?

>> Should -lldap or -lldap_r be added to pg_config --libs?
>
> You have a mistaken idea of the purpose of pg_config --libs.
> It exists to record what LIBS was at build time, not more,
> not less.  It is certainly not intended as a guide to how
> to link libpq.

*nods* Thanks for the clarification.

Yours,
Laurenz Albe


pgsql-hackers by date:

Previous
From: Gregory Stark
Date:
Subject: Re: Fixed length data types issue
Next
From: Alvaro Herrera
Date:
Subject: Re: Fixed length data types issue