Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Editing RPATH of Perl module XML::Parser

by virtualdj (Initiate)
on Dec 11, 2011 at 14:03 UTC ( [id://942947]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, this question follows the solved one with node id 942437. On a Debian VM I've compiled the latest Perl and installed a lot of CPAN modules - including XML::Parser - into a custom folder /root/perl5.

Now I want to copy that folder on a QNAP NAS with embedded Linux (on a folder named /share/FTP/xmltv) and, following the advice of building Perl from sources by Eliya, it works quite perfectly.

There is only a problem: I'm forced to export LD_LIBRARY_PATH to run XML::Parser and that's not what I want because I want to use my spefic versions of the libraries (on /share/FTP/xmltv/lib) and not those on the QNAP (/usr/lib). Look at this code:

[/share/FTP/xmltv/bin] # export PERL5LIB=/share/FTP/xmltv/lib:/share/F +TP/xmltv/lib/site_perl [/share/FTP/xmltv/bin] # ./perl -e "use XML::Parser" [/share/FTP/xmltv/bin] # find .. -name Expat.so ../lib/site_perl/5.14.2/i686-linux/auto/XML/Parser/Expat/Expat.so [/share/FTP/xmltv/bin] # find .. -name Expat.so | xargs ldd linux-gate.so.1 => (0xb770b000) libexpat.so.1 => /usr/lib/libexpat.so.1 (0xb76d4000) libc.so.6 => /lib/libc.so.6 (0xb75a0000) /lib/ld-linux.so.2 (0xb770c000) (this is NOT correct because of /usr/lib...) [/share/FTP/xmltv/bin] # export LD_LIBRARY_PATH=/share/FTP/xmltv/lib [/share/FTP/xmltv/bin] # find .. -name Expat.so | xargs ldd linux-gate.so.1 => (0xb7753000) libexpat.so.1 => /share/FTP/xmltv/lib/libexpat.so.1 (0xb771c00 +0) libc.so.6 => /lib/libc.so.6 (0xb75e2000) /lib/ld-linux.so.2 (0xb7754000) [/share/FTP/xmltv/bin] # ./perl -e "use XML::Parser" (this works but only because I've exported LD_LIBRARY_PATH) [/share/FTP/xmltv/bin] # find .. -name Expat.so | xargs readelf -d | g +rep RPATH 0x0000000f (RPATH) Library rpath: [/root/perl5/lib]

If you see the RPATH of the Expat.so library, which should be part of XML::Parser, it corresponds to the path of the Debian Virtual Machine where I've compiled the module.

I want to have a single root folder which can be placed anywhere (in this case /share/FTP/xmltv) on the NAS from which I can launch ./bin/perl (after exporting PERL5LIB) and all the modules have to look for their libraries inside ./lib.

I think that this could be done by specifying LDFLAGS="-R$ORIGIN/../lib" but while it does work for C, I'm not able to do this with Perl/CPAN. How can I do?

I've compiled XML::Parser in this way on the VM:

debian:~/dev# cd expat-2.0.1 debian:~/dev/expat-2.0.1# LDFLAGS="-R$ORIGIN/../lib" ./configure --pre +fix=/root/perl5 debian:~/dev/expat-2.0.1# make && make install debian:~/dev/expat-2.0.1# cd .. debian:~/dev# cpan cpan[1]> look XML::Parser debian:~/.cpan/build/XML-Parser-2.41-dCfdKY# export LD_LIBRARY_PATH=/r +oot/perl5/lib debian:~/.cpan/build/XML-Parser-2.41-dCfdKY# perl Makefile.PL EXPATLIB +PATH=/root/perl5/lib EXPATINCPATH=/root/perl5/include debian:~/.cpan/build/XML-Parser-2.41-dCfdKY# make && make install debian:~/.cpan/build/XML-Parser-2.41-dCfdKY# exit

As I will have to do the same for XML::LibXML and XML::LibXSLT will the eventual solution work too? Thank you.

Replies are listed 'Best First'.
Re: Editing RPATH of Perl module XML::Parser
by Anonymous Monk on Dec 11, 2011 at 22:42 UTC

    think that this could be done by specifying LDFLAGS="-R$ORIGIN/../lib" but while it does work for C, I'm not able to do this with Perl/CPAN. How can I do?

    It works for perl too, simply export LDFLAGS=... or edit Makefile.PL and add it to ExtUtils::MakeMaker::WriteMakefile

    Perl/"CPAN" does not override this, so export LDFLAGS= or any other linker/compiler options should just work, every time :)

    http://perl5.git.perl.org/perl.git?a=search&h=HEAD&st=grep&s=rpath
    http://perl5.git.perl.org/perl.git?a=search&h=HEAD&st=grep&s=rpath
    http://www.gnu.org/software/libtool/manual/libtool.html#index-LDFLAGS-107

    http://www.linuxsampler.org/msys.html

    Re: Installing iodbc 0.1 via CPAN (or other means) on Mac OS 10.6

    So you could, change Rpath after the fact

    chrpath- a tool to change the DT_RPATH attribute of an executable and convert it to an DT_RUNPATH attribute
    patchELF - a small utility to modify the dynamic linker and DT_RUNPATH attribute of ELF executables.

    set it through ldflags

    export LDFLAGS=...

    link against static versions of libxml/libxslt/libexpat...

    ./configure --enable-static --disable-shared
    ./configure --enable-static --disable-shared CFLAGS=-static-libgcc prefix=/my/install/prefix
    $config{LIBS}='-l...libxml2.a -l...libiconv.a'; $config{INC}='-I...include/libxml2'; $config{DEFINE} =' -DLIBXML_STATIC '; WriteMakefile( %INFOS, %config, );

    Or when setting up your development enviroment, mirror your target directory structure with symbolic links

    ln -s itsmylocal/xmltv /.../xmltv

      Thanks for your answer but, unfortunately, it doesn't work.

      Actually I've already tried with LDFLAGS but it seems that it doesn't apply to Perl modules (I mean the compiled ".so" files that are placed inside the Perl libraries folder).

      You can see it in detail here:

      cpan[1]> look XML::Parser debian:~/.cpan/build/XML-Parser-2.41-eA1hds# export LDFLAGS="-R$ORIGIN +/../lib" debian:~/.cpan/build/XML-Parser-2.41-QQ3gvQ# export LD_LIBRARY_PATH=/r +oot/perl5/lib debian:~/.cpan/build/XML-Parser-2.41-eA1hds# perl Makefile.PL EXPATLIB +PATH=/root/perl5/lib EXPATINCPATH=/root/perl5/include Checking if your kit is complete... Looks good Writing Makefile for XML::Parser::Expat Writing MYMETA.yml and MYMETA.json Writing Makefile for XML::Parser Writing MYMETA.yml and MYMETA.json debian:~/.cpan/build/XML-Parser-2.41-QQ3gvQ# make && make install debian:~/.cpan/build/XML-Parser-2.41-QQ3gvQ# readelf -d ./blib/arch/au +to/XML/Parser/Expat/Expat.so | grep RPATH 0x0000000f (RPATH) Library rpath: [/root/perl5/lib]

      The last line shows "/root/perl5/lib" instead of the correct "../lib".

        Try LDDLFLAGS.   As it defaults to $Config{lddlflags} (i.e. perl -V:lddlflags), you have to be careful not to overwrite anything that might be in there already (in other words, whatever you specify does replace, not add/append to it).

        As a last resort, you could try OTHERLDFLAGS (which is typically unused). — Usage (in Makefile.PL):

        WriteMakefile( ... dynamic_lib => { OTHERLDFLAGS => "-Wl,-rpath,/your/lib/path" }, );

        (In the link command in the Makefile, the values are issued in the following order: $(LD) $(LDDLFLAGS) $(LDFROM) $(OTHERLDFLAGS) -o $@ $(MYEXTLIB) ... )

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://942947]
Approved by Marshall
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-29 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found