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

Hi all,
We're beating our head against a wall. Consider:

BEGIN { $ENV{"LD_LIBRARY_PATH"} = /usr/local/lib:/usr/platform/SUNW,Ultra-80 +/lib:/usr/lib"; } ... code ... $dbh = DBI->connect('DBI:Sybase:CIC7P', 'mikeraz', 'bruised_head',{ Ra +iseError => 0, PrintError => 1, PrintWarn => 1}) ;
This dies with message:
DBI 1.48-nothread default trace level set to 0x0/5 (pid 11864) -> DBI->connect(DBI:Sybase:CIC7P, mikeraz, ****, HASH(0x152e54)) -> DBI->install_driver(Sybase) for solaris perl=5.008005 pid=11864 + ruid=12647 euid=12647 install_driver(Sybase) failed: Can't load '/usr/local/lib/perl5/site_p +erl/5.8.5/sun4-solaris/auto/DBD/Sybase/Sybase.so' for module DBD::Syb +ase: ld.so.1: perl: fatal: libgcc_s.so.1: open failed: No such file o +r directory at /usr/local/lib/perl5/5.8.5/sun4-solaris/DynaLoader.pm +line 230.
but if I, before running the program set up my environment:

bash-2.05$ LD_LIBRARY_PATH=/usr/local/lib:/usr/platform/SUNW,Ultra-80/lib:/usr/lib
bash-2.05$ export LD_LIBRARY_PATH
the script runs fine.

We're at a loss for why setting LD_LIBRARY_PATH from within the script doesn't work. The script is called from a program and the UID that it operates under does not have LD_LIBRARY_PATH defined. Nor, in our corporate environment, can it be.

Suggestions?

Update: node DynaLoader and LD_LIBRARY_PATH and programatically setting the LD_LIBRARY_PATH have the answer to this question and more background on how to put it into effect.

Michael 'off to Super Search School' R

Be Appropriate && Follow Your Curiosity

Replies are listed 'Best First'.
Re: ENV setting for library loading failure
by traveler (Parson) on Jan 25, 2006 at 23:25 UTC
    LD_LIBRARY_PATH is set for the perl executable when the perl executable is started. You can set in in the perl script, but it is not going to impact the running program (e.g. perl itself). If the loader (ld.so in linux) does not know about a library when perl starts, changing the environment variable at runtime won't tell it). In other words, it's "too late". ld.so has already copied the LD_LIBRARY_PATH environment variable into is memory, started the program and left.

      So is there a work around? short of setting the environment and invoking a child copy of self? nevermind that doesn't work.

      Be Appropriate && Follow Your Curiosity
        Of course :-) If you are root on a linux machine (maybe others, dunno) you can use ldconfig to put the library directory into the system default path. You could make a shell wrapper for your script. You could make a C or other high-level language wrapper.

        I have not looked to see how to do binary plugins in perl. It can be done in C, so it can probably be done in perl. Binary plugins allow the application (perl) to link to a shared library defined at run time. I've done in in C, but there must be a perl way, Maybe someone with experience in that space can help you. In my experience it is not simple and the other techniques are likely easier to create and maintain.

        Rebuild your perl so that it looks in /usr/local/lib (I believe something along the lines of -R/usr/local/lib to the link options).

Re: ENV setting for library loading failure
by Mandrake (Chaplain) on Jan 26, 2006 at 02:05 UTC
    Doing a perl -w gives me
    syntax error at work.pl line 3, near "/usr/local" Bareword found where operator expected at work.pl line 3, near "/lib:/ +usr" (Missing operator before usr?) . . .
    I am wondering if this code did compile?
Re: ENV setting for library loading failure (link)
by tye (Sage) on Jan 26, 2006 at 09:39 UTC