Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Can't use DBD::Oracle if LD_LIBRARY_PATH Not Set In Environment

by garybiscuit (Initiate)
on Feb 06, 2013 at 17:07 UTC ( [id://1017474]=perlquestion: print w/replies, xml ) Need Help??

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

Hi,

I've successfully installed the DBI and DBD::Oracle Perl modules, but I've noticed that I can't "use DBD::Oracle;" unless my LD_LIBRARY_PATH is set in my environment before I call the Perl program that attempts to use DBD::Oracle...

# ========================================== BEGIN { $ENV{'ORACLE_HOME'} = '/my/oracle_home'; $ENV{'LD_LIBRARY_PATH'} = '/my/oracle_home/lib'; } use strict; use warnings; use DBI; use DBD::Oracle; print "Hello world!\n"; # ==========================================

...produces...

# ========================================== Can't load '/usr/perl5/5.16.2/lib/site_perl/5.16.2/sun4-solaris/auto/D +BD/Oracle/Oracle.so' for module DBD::Oracle: ld.so.1: perl: fatal: li +bclntsh.so.11.1: open failed: No such file or directory at /usr/perl5 +/5.16.2/lib/5.16.2/sun4-solaris/DynaLoader.pm line 190. at ./ecm_bounce_pusher.pl line 15. Compilation failed in require at ./test_program.pl line 8. BEGIN failed--compilation aborted at ./test_program.pl line 8. # ==========================================

... if LD_LIBRARY_PATH is NOT set in my environment first. However, if I *do* set LD_LIBRARY_PATH in the environment, the above code works fine.

Obviously I could make a wrapper script that sets LD_LIBRARY_PATH before invoking my above program, but I'd like to make my program as compact and self-reliant as possible (i.e. no wrapper script).

Is there anything I can do to be able to invoke DBD::Oracle without having to set LD_LIBRARY_PATH first in the environment?

---- MY STATS ----
OS: Solaris 10
Perl: 5.16
Oracle: 11.2.0.3 Instant Client
-------------------

Thanks,
Gary

Replies are listed 'Best First'.
Re: Can't use DBD::Oracle if LD_LIBRARY_PATH Not Set In Environment
by Corion (Patriarch) on Feb 06, 2013 at 17:27 UTC

    See Perl and paths...again :-( and the replies to it. This sounds like very much the same problem, so the solution there might help you too.

      OK. I looked at that thread. Using the "exec $0" method to re-invoke the program works (after setting LD_LIBRARY_PATH) - but that just seems a little too funky for me. Is there a "cleaner" way? (For lack of a better way of putting it).

      Thanks,
      Gary

        Yes. Write a wrapper (shell) script that sets the environment variables before invoking your Perl program.

Re: Can't use DBD::Oracle if LD_LIBRARY_PATH Not Set In Environment
by runrig (Abbot) on Feb 06, 2013 at 21:36 UTC
    What does it say if you unset LD_LIBRARY_PATH and you run:
    ldd /usr/perl5/5.16.2/lib/site_perl/5.16.2/sun4-solaris/auto/DBD/Oracl +e/Oracle.so

    If the results point to locations that don't exist, then likely your DBD::Oracle was compiled on a different system where libraries were in a different place. Now you have to set LD_LIBRARY_PATH to specify where they are on your system.

    Update: Or compile DBD::Oracle on your current system so that the Oracle.so file knows where it's libraries are. On HP-UX you can use chatr to change the paths to libraries in a .so file...don't know if the same exists on solaris (don't think so). If you're really brave, maybe you can edit the paths in the .so binary yourself :-)

Re: Can't use DBD::Oracle if LD_LIBRARY_PATH Not Set In Environment
by Anonymous Monk on Feb 07, 2013 at 00:34 UTC

    Hi,

    Could you not just set the variable up in the users environment and leave it there all the time?

    Then you don't have to worry about it.

    J.C.

Re: Can't use DBD::Oracle if LD_LIBRARY_PATH Not Set In Environment
by Ea (Chaplain) on Feb 07, 2013 at 15:10 UTC
    I don't think you absolutely need the DBD::Oracle line. DBI should load the correct module when you connect.

    My personal solution has been to hide connection details in a module which always gets installed in The Right Place, has a home for tests and makes scripts clear and concise with subs like this

    sub setup_environment { my $server = get_server_name(); for my $env ( %{$environment{$server}} ) { $ENV{$env} = $environment{$server}->{$env}; } return scalar keys %{$environment{$server}}; }
    I use it to cache database handles and such. It's not your perfect solution, but it works for me.

    Sometimes I can think of 6 impossible LDAP attributes before breakfast.
Re: Can't use DBD::Oracle if LD_LIBRARY_PATH Not Set In Environment
by Plankton (Vicar) on Feb 06, 2013 at 19:58 UTC
    When I run into .so problems, I run sudo ldconfig and sometimes that helps. But I run RHEL, not sure if there is a equivalent to ldconfig on Solaris.
Re: Can't use DBD::Oracle if LD_LIBRARY_PATH Not Set In Environment
by Anonymous Monk on Feb 07, 2013 at 20:10 UTC
    Does
    use strict; use warnings; use lib '/my/oracle_home/lib'; use DBI; use DBD::Oracle;
    have any effect? Or is this unrelated?

Log In?
Username:
Password:

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

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

    No recent polls found