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

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

by jrw (Monk)
on Jul 26, 2019 at 03:43 UTC ( [id://11103414]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Why must LD_LIBRARY_PATH be defined outside script for DBD::Oracle?
in thread Why must LD_LIBRARY_PATH be defined outside script for DBD::Oracle?

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.

  • Comment on Re^3: Why must LD_LIBRARY_PATH be defined outside script for DBD::Oracle?
  • Download Code

Replies are listed 'Best First'.
Re^4: Why must LD_LIBRARY_PATH be defined outside script for DBD::Oracle?
by holli (Abbot) on Jul 26, 2019 at 06:59 UTC
      ... $ENV{LD_LIBRARY_PATH} = "$ENV{ORACLE_HOME}/lib"; ... exec 'env',$0,@ARGV; # <<<< brrrrr!

      Notice that all this solution does is a) on startup, set the environment variable LD_LIBRARY_PATH to what you want (that's a mistake: it should have appended to it, not set=replace!) and b) re-spawn (=replace current process with new, which keeps same PID) perl script via exec which will take into consideration the new value of the environment variable (ideally) while c) guarding against re-spawning ad-infinitum by setting yet another environment variable/flag. Yikes!

      Using a shell script wrapper (contained in the question) does the same and in my opinion more cleanly.

      Here is my suggestion: tell DynaLoader where to additionally look for libraries after executing your perl script but before loading troublesome module. This is what the manual says on how this works:

      @dl_library_path should also be initialised with any other directories that can be determined from the environment at runtime (such as LD_LIBRARY_PATH for SunOS <<the OS Pericles used during the Pelloponisian War ;)>>).
      
      After initialisation @dl_library_path can be manipulated by an application using push and unshift before calling dl_findfile(). Unshift can be used to add directories to the front of the search order either to save search time or to override libraries with the same name in the 'normal' directories.
      
      The load function that dl_load_file() calls may require an absolute pathname. The dl_findfile() function and @dl_library_path can be used to search for and return the absolute pathname for the library/object that you wish to load.
      

      Notice the "that can be determined from the environment at runtime". That's why you need to re-spawn after modifying said enviroment variable. Anyway, I can't test it but pushing to @dl_library_path should do the trick. See Cleanly adding a directory to DynaLoader's search path? how to do that. For me, this is the cleanest solution.

      bw, bliako

      Are you using Solaris?
      /me looks at the original question:
      On Linux (currently testing RHEL6.5)...
      But the (currently) last post on that thread notes that this behavior is found in both Solaris and Linux, so it likely applies anyhow.
        Yes, thank you for pointing that out. I didn't realize RHEL is Red Hat. I mean I know that, but it's 10am and 31°C already. Thinking is a bit like walking through mollasses :)


        holli

        You can lead your users to water, but alas, you cannot drown them.
Re^4: Why must LD_LIBRARY_PATH be defined outside script for DBD::Oracle?
by Anonymous Monk on Jul 26, 2019 at 07:11 UTC

    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?

    But are you aware the that is how LD_LIBRARY_PATH works for all programs? That its not a perl variable?

    For every software Why? question, the answer is simple, because its written that way :)

    The LD in LD_LIBRARY_PATH stands for one of the few/many "ld.so" , there is no PERL_ prefix

    All docs I read about LD_LIBRARY_PATH mention its for testing/debugging...

    If that answers the question, then great :)

    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.

    aix? :) Internet says instead of -Wl,--rpath use LIBPATH= or -Wl,-blibpath

Log In?
Username:
Password:

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

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

    No recent polls found