Setting LD_LIBRARY_PATH in Perl

Hi All:

I want to set LD_LIBRARY_PATH in perl. I am doing the following:

$libpath = '/users/devtest/tmp/xoslib-5.0.0.1/lib/xoslib';
$ENV{LD_LIBRARY_PATH} .= ':' . $libpath;

Please let me know how to make this work.

Best Regards,

Sunnybrad
sunnybradAsked:
Who is Participating?
 
mrjoltcolaConnect With a Mentor Commented:
I did post a solution for that exact problem.

The issue is your Perl interpreter runs in its own environment. Once it exits, the environment goes back to the original shell's env.

If you want it permanently changed, add it to your .profile or /etc/profile
0
 
TintinCommented:
What you have looks correct.

What makes you think it isn't working?
0
 
mrjoltcolaCommented:
Likely you are having the problem that by the time your script needs LD_LIBRARY_PATH, the loader has already run.

So do this (from Perl monks http://www.perlmonks.org/index.pl?node_id=126575)

Essentially set it, then exec yourself.

my $interactive = TRUE if ( ! system( 'tty -s' ) / 256 );

unless ($interactive)
{
   unless ( $ENV{BEGIN_BLOCK} ) {
      $ENV{"LD_LIBRARY_PATH"} = '/users/devtest/tmp/xoslib-5.0.0.1/lib/xoslib';
      $ENV{BEGIN_BLOCK} = 1;
      exec 'env',$0,@ARGV;
   }
}

Open in new window


or

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;
    }
}

Open in new window


Again, credit goes to perl monks (tye and ghodmode), just referencing the sample I've used.
0
 
sunnybradAuthor Commented:
Hi Tintin:

After the program runs I don't see the path getting set.

pot:110> env | grep LD_L
LD_LIBRARY_PATH=/usr/X11R6/lib

Please suggest a solution.

Best Regards

Sunnybrad
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.