http://qs321.pair.com?node_id=603522

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

I have a script which uses Business::OnlinePayment::PayflowPro which in turn uses a .so file from PayflowPro. It's easy enough for Dynaloader to link to it if it's in the standard lib location, but I want this project to be self-contained, so I'm not putting it in the standard location.

I can fix this if I set $ENV{LD_LIBRARY_PATH} in my shell or the process that spawns this script, but I would like to be able to do it from within my script, but it doesn't work like that.

I assume that there's some DynaLoader incantation I can perform that will work, but I can't quite get my finger on it. Any ideas?


-- More people are killed every year by pigs than by sharks, which shows you how good we are at evaluating risk. -- Bruce Schneier

Replies are listed 'Best First'.
Re: linking to .so file in non-standard location
by chromatic (Archbishop) on Mar 07, 2007 at 03:51 UTC

    Push the appropriate directory onto @DynaLoader::dl_library_path before using the module which loads the .so file. DynaLoader's documentation is a little unclear about this, but it's there if you know what to look for.

      I tried this
      BEGIN { require DynaLoader; push(@DynaLoader::dl_library_path, '/custom/path'); require Business::OnlinePayment::PayflowPro; }
      Which seems like it ought to work, but doesn't. I still get the same failure: Can't load 'lib/i686-linux/auto/PFProAPI/PFProAPI.so' for module PFProAPI: libpfpro.so: cannot open shared object file: No such file or directory at /usr/local/lib/perl5/5.8.8/i686-linux/DynaLoader.pm line 230. I even verified that DynaLoader can load the libpfpro.so module on it's own by calling DynaLoader::dl_findfile('libpfpro.so'); which returns the correct path. Any further advice?

      -- More people are killed every year by pigs than by sharks, which shows you how good we are at evaluating risk. -- Bruce Schneier
Re: linking to .so file in non-standard location
by Sidhekin (Priest) on Mar 06, 2007 at 22:44 UTC

    Ideas? Sure. Good ideas? Not so sure. :)

    To start this thing though: First thing I'd try would be starting my script with this:

    # before loading anything: BEGIN { unless ($ENV{LD_LIBRARY_PATH}) { $ENV{LD_LIBRARY_PATH} = '/the/necessary/path/info'; exec $^X, $0, @ARGV; # add '-T' if necessary } }

    If that works, I'd try without the exec, just to make sure.

    print "Just another Perl ${\(trickster and hacker)},"
    The Sidhekin proves Sidhe did it!