jklowden has asked for the wisdom of the Perl Monks concerning the following question:

Building DBD::Sybase, I want to add /usr/local/dept/lib to the RPATH in the .so. Defining CCFLAGS or LDDLFLAGS on the Makefile.PL command line doesn't work. Mr. Peppler suggested I try here. I will forward any fix to him for future versions.

A normal invocation produces a link command like this:
gcc -L/usr/local/dept/lib \ -shared \ -O2 \ -g \ -pipe \ -Wall \ -Wp,-D_FORTIFY_SOURCE=2 \ -fexceptions \ -fstack-protector \ --param=ssp-buffer-size=4 \ -m64 \ -mtune=generic Sybase.o dbdimp.o \ -o blib/arch/auto/DBD/Sybase/Sybase.so
I can add the RPATH manually by relinking thus:
$ sh -x relink && readelf -d blib/arch/auto/DBD/Sybase/Sybase.so | gre +p -i rpath + gcc -L/usr/local/dept/lib -Wl,-R/usr/local/dept/lib -shared -O2 -g - +pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --p +aram=ssp-buffer-size=4 -m64 -mtune=generic Sybase.o dbdimp.o -o blib/ +arch/auto/DBD/Sybase/Sybase.so 0x000000000000000f (RPATH) Library rpath: [/usr/local/de +pt/lib]
but using LDDLFLAGS damages the command line:
$ perl Makefile.PL PREFIX=$DEPT/perl LDDLFLAGS=-Wl,-R$DEPT/lib < answe +rs && rm -f nohup.out && nohup make || grep ^gcc nohup.out | tail -1 Unknown Client Library version - assuming FreeTDS. ... Writing Makefile for DBD::Sybase nohup: appending output to `nohup.out' gcc -Wl,-R/usr/local/dept/lib Sybase.o dbdimp.o -o blib/arch/auto/DB +D/Sybase/Sybase.so
Many thanks. --jkl

Replies are listed 'Best First'.
Re: adding RPATH to Sybase.so
by almut (Canon) on Jan 12, 2010 at 20:14 UTC

    I think you're out of luck with adding to LDDLFLAGS, but you could try setting

    WriteMakefile( ... dynamic_lib => { OTHERLDFLAGS => '-Wl,-rpath,/usr/local/dept/lib' +}, ... );

    in Makefile.PL — which should achieve the same effect.  OTHERLDFLAGS is being inserted a little later on the linker command line, i.e.  $(LD)  $(LDDLFLAGS) $(LDFROM) $(OTHERLDFLAGS) -o $@ $(MYEXTLIB) ..., but that's not a problem, as it doesn't matter at which position the rpath option occurs.

      The story is there's no general answer. If LDDLFLAGS is overridden on the command line (LDDLFLAGS=-R/yada/yada) the value replaces what would ordinarily be there, because it overrides the value set by the hash passed to WriteMakefile in Makefile.PL. That is, WriteMakefile examines @ARGV for variable=value pairs and takes what it finds as overrides. (Observed behavior; I can't find the source code.)

      To extend LDDLFLAGS, one would have to know how Makefile.PL sets it. I don't know of any way to do that except by examining the sources. (Afaik there's no MakeMaker option to print variable values, although I suppose -qp could be passed to make(1) to do that instead.)

      Peeking inside Makefile.PL, one can easily see that LDDLFLAGS is set to the contanenation "-L$Sybase/lib" and $Config::Config{lddlflags}. So the hack would be something like: perl Makefile.PL LDDLFLAGS=$(perl -e'use Config; print qq("-L$ENV{SYBASE}/lib $Config{lddlflags} -R/yada")') which I guess is OK.

      Extending your suggestion, I added a new --other_dlflags option to Makefile.PL and sent a patch to Michael Peppler. Perhaps 1.10 will be a little easier to use. :-)