Opened 13 years ago

Closed 13 years ago

#3708 closed defect (fixed)

MapServer introduces unnecessary direct link against libpq dependencies

Reported by: warmerdam Owned by: warmerdam
Priority: normal Milestone: 6.0 release
Component: PostGIS Interface Version: unspecified
Severity: normal Keywords:
Cc: aboudreault

Description

If I configure and build mapserver against Postgresql I get the following in the makefile on linux:

POSTGIS_LIB=  -L/usr/lib -lpq -lpgport -lxslt -lxml2 -lpam -lssl -lcrypto -lkrb5 -lcom_err -lgssapi_krb5 -lz -lreadline -lcrypt -ldl -lm 

But in fact, all that is needed is "-L/usr/lib -lpq". For that matter, that is all that actually gets used in the AC_CHECK_LIB call in configure as seen from this line in the config.log:

configure:11875: checking for PQserverVersion in -lpq
configure:11905: gcc -o conftest -g -O2 -fPIC   -L/usr/lib conftest.c -lpq  -ljpeg  -lm -lstdc++  >&5
configure:11911: $? = 0

The extra linking wouldn't matter much, but on some systems it requires the -dev packages be installed for all the subpackages like libpam, etc. I would add this is a relatively recent regression, some time in the 5.6.x series I think.

The basic problem is that pg_config --libs is defined to return the libraries libpq was linked against rather than the libraries that the libpq using application should link against.

I would suggest we first try AC_CHECK_LIB against just -lpq and if that fails, add the full set of dependent libs to LDFLAGS and try again.

I will take a crack at this and prepare a patch.

Attachments (1)

pg.patch (1.8 KB ) - added by warmerdam 13 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by tbonfort, 13 years ago

Frank,

I would suggest to first add the output of pg_config --libdir to a -L linker flag before doing an AC_CHECK_LIB(pq)

regards, thomas

comment:2 by warmerdam, 13 years ago

Thomas,

Agreed. This code is already in place and would remain.

comment:3 by warmerdam, 13 years ago

Cc: aboudreault added

Adding Alan since he added the code I object to in r9159. Alan - any comment on why it was needed?

by warmerdam, 13 years ago

Attachment: pg.patch added

comment:4 by warmerdam, 13 years ago

It looks like the old postgis testing didn't use AC_CHECK_LIB to see if we could actually link with -lpq, instead it just used it to test if we had the serverversion function. I have restructured to first test link against -lpq. If that fails it retries with the dependent libs (pg_config --libs). Assuming one of those has succeeded it then tests for the versioninfo function.

With this arrangement I was able to link minimally against libpq.so. But if I hid that and kept libpq.a it fell back to using the dependent libs. (it still failed actually because for some reason pg_config --libs did not include the dependency on libldap but I hacked around that for a proof of concept).

Should I go ahead and apply this in trunk?

comment:5 by aboudreault, 13 years ago

Frank, I don't remember exactly why I made this change...... but I certainly hit something to decide to do so. Hovewer, I have no objection to apply your patch if everything build well.

comment:6 by pramsey, 13 years ago

Owner: changed from pramsey to warmerdam

Go ahead and apply and close, looks good to me.

comment:7 by warmerdam, 13 years ago

Resolution: fixed
Status: newclosed

Patch applied in trunk (r11199). I did not regenerate configure since I have quite a different version of autoconf from what is usually used.

Note: See TracTickets for help on using tickets.