Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: (tye)Re: programatically setting the LD_LIBRARY_PATH

by GhodMode (Pilgrim)
on Apr 08, 2004 at 13:16 UTC ( [id://343603]=note: print w/replies, xml ) Need Help??


in reply to (tye)Re: programatically setting the LD_LIBRARY_PATH
in thread programatically setting the LD_LIBRARY_PATH

This is an old thread, but I've often had reason to refer back to it. Hopefully someone will also find the following useful.

Tye's solution works perfectly. It seems to be the best solution for cron jobs on a server with a diverse environment. The only problem is the the BEGIN block sort of breaks the use of perl -c and perl -d. If I understand correctly, it's because those options sort of wrap the existing code in code that will just compile or debug the existing code.

The following works, but only if the environment variables don't need to be set before the modules are loaded. Naturally, on a Windows system you will need to find an alternative method of determining an interactive shell...

my $interactive = TRUE if ( ! system( 'tty -s' ) / 256 ); unless ($interactive) { unless ( $ENV{BEGIN_BLOCK} ) { $ENV{"ORACLE_HOME"} = '/opt/oracle/product/9.2.0'; $ENV{"LD_LIBRARY_PATH"} = '/opt/oracle/product/9.2.0/lib'; $ENV{BEGIN_BLOCK} = 1; exec 'env',$0,@ARGV; } }

Credit for this goes to one of my (non-perlmonk) co-workers. I'm just taking the credit :D I've been using a variation of Tye's code until now.

--
-- GhodMode

Replies are listed 'Best First'.
Re^3: programatically setting the LD_LIBRARY_PATH
by gordoste (Initiate) on Nov 29, 2005 at 04:23 UTC
    If you're doing this because a Perl module has a dependency on a native library (e.g. XML::LibXML), and you need to load the library from a non-default path (e.g. you have a version of libxml2 not in /lib or /usr/lib) and you want to avoid modifying LD_LIBRARY_PATH in a wrapper script or some kind of pseudo-wrapper like that shown above, there is another alternative. In the .bs file for the module, place a call to dl_load_file passing the absolute name of the native library. I used an environment variable to store my custom library path:
    # Need to find libxml2. Cannot set LD_LIBRARY_PATH as it is already # cached by the linker. So we load libxml2 BEFORE loading # XML::LibXML's library. dl_load_file($ENV{FOO_PATH} . '/lib/os/libxml2.so.2');
      I was hoping I could use this if LD_LIBRARY_PATH was already set and it was finding the wrong version of the library in the path. Alas, it still finds and loads the wrong version after specifying the correct version here in the bootstrap file. If only there was a way to specify here to skip some of the other bootstrapping process.
      Evil! Thank you very much for sharing your solution!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-06-18 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.