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/Oracle.so'
for module DBD::Oracle: libclntsh.so.11.1: cannot open shared object file:
No such file or directory at
/usr/lib64/perl5/5.8.5/x86_64-linux-thread-multi/DynaLoader.pm 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
[oracle ~]$ perl -e 'use DBD::Oracle; print $DBD::Oracle::VERSION,"\n";'
1.15
But if I do the following instead in the Perl script, it does not work? How
to set the LD_LIBRARY_PATH then?
$ENV{ORACLE_HOME}=$ORACLE_HOME;
$ENV{ORACLE_SID}=$ORACLE_SID;
$ENV{PATH}="$ORACLE_HOME/bin:$PATH";
$ENV{LD_LIBRARY_PATH}="$ORACLE_HOME/lib";
FYI, 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.
If you're going to use "use DBD::Oracle;" in the script then you'll need to
put these statements in a BEGIN block:
[code]
use vars qw($ORACLE_HOME $ORACLE_SID);
BEGIN
{
$ORACLE_HOME = ...;
$ORACLE_SID = ...;
$ENV{ORACLE_HOME}=$ORACLE_HOME;
$ENV{ORACLE_SID}=$ORACLE_SID;
$ENV{PATH}="$ORACLE_HOME/bin:$PATH";
$ENV{LD_LIBRARY_PATH}="$ORACLE_HOME/lib";
}
use DBD::Oracle;
[/code]
That's because "use" is executed at compile-time instead of run-time.
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
"The Human Hacking Field Guide" - http://shlom.in/hhfg
God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
> You will have to set those values before your modules load.
>
> So you should stick them in the BEGIN and that should work
... except where it doesn't, such as on Solaris for example. Here,
LD_LIBRARY_PATH (at least) really does need to be set before the process
starts. You can do this by writing a shell wrapper, or re-execing your
perl script if the value is not already set.
You're using linux and I'm not sure if this sort of messing about is
required there.
> http://www.compuspec.net/reference/language/perl/BEGIN_and_END.shtml
>
> cheers
> John Scoles
> --
> Catch Alex & Sheeri at ODTUG/Kaleidoscope - June 27 - July 1.
> Hear Sheeri speak or email eve...@pythian.com to meet with Pythian.
--
Paul Johnson - pa...@pjcj.net
http://www.pjcj.net
Have you considered doing a require instead of a use. With require, the loading is done at run time, and would be governed by the setting of LD_LIBRARY_PATH, at the time the require statement is executed. Just set LD_LIBRARY_PATH before doing the require.
--Marilyn
> On May 28, 2010, at 9:33 AM, Paul Johnson wrote:
>
> > On Fri, May 28, 2010 at 06:14:38AM -0400, John Scoles wrote:
> >
> >> You will have to set those values before your modules load.
> >>
> >> So you should stick them in the BEGIN and that should work
> >
> > ... except where it doesn't, such as on Solaris for example. Here,
> > LD_LIBRARY_PATH (at least) really does need to be set before the process
> > starts. You can do this by writing a shell wrapper, or re-execing your
> > perl script if the value is not already set.
> Have you considered doing a require instead of a use. With require, the
> loading is done at run time, and would be governed by the setting of
> LD_LIBRARY_PATH, at the time the require statement is executed. Just set
> LD_LIBRARY_PATH before doing the require.
I'm afraid that you may have misunderstood what I wrote. There are
times when you really do need to set the variable before the process
starts.
Yeah, using a wrapper shell script to setup the environment is always
a good idea. I have seen too many Perl scripts (and C programs) fail
miserably when run by cron because they assumed some environment would
be present. This would also be a good place to set PERL5LIB and any
other variables you need to exist.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
I did not misunderstand what you wrote. My reasoning was that the
thing being
loaded is a shared object (.so file). The system loader (ld) has to
be invoked for loading
a shared object. That seems to me to require a separate process, with
an environment
stack inherited from the Perl process that invokes it. I was also
assuming that setting
an environment variable at run time would set the environment for the
Perl process
that is executing the Perl program. However, I did not test it. I
will test it and see what happens.
--Marilyn