http://qs1969.pair.com?node_id=126587


in reply to programatically setting the LD_LIBRARY_PATH

Note that doing a Super Search for articles that mention LD_LIBRARY_PATH might have gotten you enough information to get past this problem. I didn't find the answer neatly wrapped up (but I only looked at a couple of the hits), though, so here is one...

You likely can't set LD_LIBRARY_PATH from within the running process no matter how early you do it as the linker/loader has already started loading the process and has cached the value of LD_LIBRARY_PATH. Previously I've work around this by execing the perl executable so that it must reload and will see the new LD_LIBRARY_PATH that I have set. On some operating systems, even that isn't enough as the linker/loader notices that we are execing the same executable and doesn't bother to reinitialize. For such cases, you have to exec a different executable and ask it to exec perl for you.

Something close to the following should work:

BEGIN { my $need= '/usr/local/sybase/lib'; my $ld= $ENV{LD_LIBRARY_PATH}; if( ! $ld ) { $ENV{LD_LIBRARY_PATH}= $need; } elsif( $ld !~ m#(^|:)\Q$need\E(:|$)# ) { $ENV{LD_LIBRARY_PATH} .= ':' . $need; } else { $need= ""; } if( $need ) { exec 'env', $^X, $0, @ARGV; } }

        - tye (but my friends call me "Tye")