Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?


by sarf13 (Beadle)
on Jan 09, 2012 at 06:07 UTC ( #946944=perlquestion: print w/replies, xml ) Need Help??
sarf13 has asked for the wisdom of the Perl Monks concerning the following question:

HI All
Can someone advise how to set LD_LIBRARY_PATH from within the Perl scripts?
If I set LD_LIBRARY_PATH from the command line, all is okay
oracle ~$ perl -e 'use DBD::Oracle; print $DBD::Oracle::VERSION,"\n";' Can't load '/oracle/product/db/11.1/perl/lib/site_perl/5.8.3/x86_64-linux-thread-multi/auto/DBD/Oracle/' for module DBD::Oracle: cannot open shared object file: No such file or directory at /usr/lib64/perl5/5.8.5/x86_64-linux-thread-multi/ line 230. at -e line 1 Compilation failed in require at -e line 1. BEGIN failed--compilation aborted at -e line 1. oracle ~$ export LD_LIBRARY_PATH=/oracle/product/db/11.1/lib
How to set the LD_LIBRARY_PATH then?
the script is to run from a cron which is why am setting LD_LIBRARY_PATH in the script.
Any response will be very much appreciated. Thanks in advance. Thank u all monks...
i got resolve this issue...

Replies are listed 'Best First'.
Re: How to set LD_LIBRARY_PATH
by mbethke (Hermit) on Jan 09, 2012 at 07:16 UTC

    It looks like something is wrong with your installation, i.e. the DBD::Oracle module is installed in a system directory but not its dependency. That's something for the sysadmin to fix---link the library to a dir in the standard library path, extend the path in /etc/profile or something.

    As a workaround, you can specify a full shell command line including variable setting in a crontab as well. Or do something evil like (untested, prone to DOSing the system if something goes wrong, and hopefully unnecessary anyway)

    eval "use DBD::Oracle;"; if($@) { $ENV{LD_LIBRARY_PATH} = '/where/ever/the/hell'; exec $0 @ARGV; }
Re: How to set LD_LIBRARY_PATH
by Anonymous Monk on Jan 09, 2012 at 06:40 UTC
Re: How to set LD_LIBRARY_PATH
by Khen1950fx (Canon) on Jan 09, 2012 at 06:37 UTC
    I don't currently have Oracle installed, so this is untested.
    #!/usr/bin/perl -l BEGIN { $ENV{ORACLE_HOME}=$ORACLE_HOME; $ENV{PATH}="$ORACLE_HOME/bin:$PATH"; $ENV{LD_LIBRARY_PATH}="$ORACLE_HOME/lib"; } use strict; use warnings; use DBD::Oracle; print "$DBD::Oracle::VERSION";

      I can't think of anything to try this with right now but it's unlikely to work. Dynamically loaded modules use dlopen(3) to open libraries, whose Linux manpage says:

      o If, at the time that the program was started, the environment vari +able LD_LIBRARY_PATH was defined to contain a colon-separated list of d +irectories, then these are searched.

      Note the "at the time that the program was started" bit, which means the binary i.e. the Perl interpreter here.

      That's what I thought, too. But as I understand it now, it's unlikely to work if you set ENV after you load the modules, but it likely will work if set before you load the modules.

        but it likely will work if set before you load the modules.

        Won't, it has to be set before you run perl

Re: How to set LD_LIBRARY_PATH
by runrig (Abbot) on Jan 09, 2012 at 17:11 UTC
    I recently posted a solution to this very problem.

    Of course, another solution would be to write a shell wrapper for your script that sets LD_LIBRARY_PATH to the correct value before launching your script.

      Whow, there's a reference to this thread that describes this exact problem. Seems Orrable has been doing it like this since the last millennium ...
Re: How to set LD_LIBRARY_PATH
by Anonymous Monk on Jan 09, 2012 at 13:04 UTC
    I would think that this is something that you should "detect" but not "attempt to fix," because now your "fix" is buried where the sysadmin's won't know where to find it. Loader library-paths should be set at only a few well-established places, e.g. profile scripts. An ill-thought-out "workaround," even though it might "make my program work now," might be a big future headache and mask the existence of a root-problem without solving it. Discuss the matter next with your sysadmins and/or management.
      I disagree. LD_LIBRARY_PATH should not have to be set at all, but if it must be set, then just set it in as localized a place as possible to run what you need to run.
Re: How to set LD_LIBRARY_PATH
by cavac (Deacon) on Jan 09, 2012 at 16:22 UTC

    Any response will be very much appreciated.

    Please use

    tags and basic formatting.

    "Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupidů and I went ahead anyway." (Crow in "MST3K The Movie")

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://946944]
Approved by GrandFather
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2017-09-25 07:07 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (277 votes). Check out past polls.