Search code examples
perlpostgresqlstatic-linkingdbdmakemaker

Statically Linking DBD::Pg (against libpq.so) but Dynamically Against Perl?


I'm trying to build DBD::Pg on a linux host via the Makefile.PL; my requirements are such that I must be able to dynamically link against perl, but statically link against libpq.so (since it may not be available on all boxes).

Is there an easy way to do this? I have tried changing the link options in the LIBS directive of the Makefile.PL but MakeMaker ignores my options.


Solution

  • IMO you've mis-specified your requirements.

    You do not need to statically link to libpq just because it might not be available on all systems.

    What you should generally do instead is dynamically link to libq and either set LD_LIBRARY_PATH in a wrapper script or use rpath linking so that libpq can be found.

    Be aware though that whether statically or dynamically linking, if some other module loads a libpq into the same Perl you'll either get two incompatible libpqs linked into the same executable (boom) or one of the modules using a libpq other than the one it was compiled against (also boom). If you use rpath linking, ld.so's awareness of link scopes might let you get away with it, but setting LD_LIBRARY_PATH will almost certainly cause issues.

    You might want to look into using rpath with $ORIGIN.