Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Why must LD_LIBRARY_PATH be defined outside script for DBD::Oracle?

by jrw (Monk)
on Jul 25, 2019 at 23:38 UTC ( [id://11103401]=perlquestion: print w/replies, xml ) Need Help??

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

On Linux (currently testing RHEL6.5), it appears that LD_LIBRARY_PATH must be defined/exported *outside* my script in order to load DBD::Oracle successfully. This is not so on AIX (LIBPATH), and I wasn't expecting it on Linux either. Setting $ENV{LD_LIBRARY_PATH} in a BEGIN block at the top of my script gets the standard
install_driver(Oracle) failed: Can't load '/home/jrw/perl_dbi/linux/li +b/perl5/x86_64-linux-thread-multi/auto/DBD/Oracle/Oracle.so' for modu +le DBD::Oracle: libclntsh.so.18.1: cannot open shared object file: No + such file or directory at /usr/lib64/perl5/DynaLoader.pm line 200. at (eval 38) line 3
whereas exporting LD_LIBRARY_PATH *before* running perl -e allows the script to succeed. Does DynaLoader cache the initial LD_LIBRARY_PATH during script startup? Or is something else going on? Test script:
export DIR=/home/jrw/perl_dbi/linux unset LD_LIBRARY_PATH # export LD_LIBRARY_PATH=$DIR/oracle_instantclient perl -e ' use strict; use warnings; BEGIN { $ENV{LD_LIBRARY_PATH} = "$ENV{DIR}/oracle_instantclient" } use lib "$ENV{DIR}/lib/perl5"; use DBI; my @drivers = DBI->available_drivers; print "Drivers = @drivers\n"; foreach my $driver (@drivers) { my @databases = DBI->data_sources($driver); print " Driver: $driver, data sources = @databases\n"; } '

Replies are listed 'Best First'.
Re: Why must LD_LIBRARY_PATH be defined outside script for DBD::Oracle?
by syphilis (Archbishop) on Jul 27, 2019 at 00:07 UTC
    BEGIN { $ENV{LD_LIBRARY_PATH} = "$ENV{DIR}/oracle_instantclient" }

    Has $ENV{DIR} been set correctly ?
    I would include, inside that BEGIN{} block, a check to verify that $ENV{LD_LIBRARY_PATH} has in fact been set to its expected value - and have the script die() if the check fails.

    Cheers,
    Rob
Re: Why must LD_LIBRARY_PATH be defined outside script for DBD::Oracle?
by Anonymous Monk on Jul 26, 2019 at 00:32 UTC
    Its a hack
        I'm well aware of the evils of LD_LIBRARY_PATH. But that was not my question, which was: why does Perl on Linux seem to require that LD_LIBRARY_PATH be defined before the script starts rather than being defined in a BEGIN block before DBD is loaded?

        P.S. If anyone can tell me how to do the equivalent of setting rpath in the .so files produced by AIX's xlc compiler, then I could go that route. But since I currently have to set LIBPATH for AIX (which I can set *inside* the script as opposed to prior to running the script like I have to do on Linux), then I'll stick to trying to set LD_LIBRARY_PATH on Linux.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2024-04-19 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found