Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

linking to .so file in non-standard location

by mpeters (Chaplain)
on Mar 06, 2007 at 22:26 UTC ( #603522=perlquestion: print w/replies, xml ) Need Help??
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/' for module PFProAPI: cannot open shared object file: No such file or directory at /usr/local/lib/perl5/5.8.8/i686-linux/ line 230. I even verified that DynaLoader can load the module on it's own by calling DynaLoader::dl_findfile(''); 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!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://603522]
Approved by Sidhekin
Front-paged by friedo
[erix]: well, dutch royals are germans, really
[choroba]: Utrecht? Is that where we made the trip, LanX?
[erix]: we should really dupm the lot, but I got no say in the matter :)
[LanX]: yeah its a religious mafia , the only two big calvinist houses are dutch and prussian. ..
[LanX]: choroba yes
[erix]: Utrecht has a beautiful old center, and less mass-tourism than Amsterdam
[erix]: next time, drop by :)
[LanX]: religion is also the reason how the house of Hanover aquire the English throne, all other candidates on succession where catholics...
[erix]: Henry VIII has a lot to answer for :P
[LanX]: erix sure next time you miss a conference nearby we drop by ...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2017-12-15 16:36 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (439 votes). Check out past polls.