?
Solved

Setting LD_LIBRARY_PATH in Perl

Posted on 2011-04-29
4
Medium Priority
?
835 Views
Last Modified: 2013-12-06
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
0
Comment
Question by:sunnybrad
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 35495295
What you have looks correct.

What makes you think it isn't working?
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 35495305
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
 

Author Comment

by:sunnybrad
ID: 35495326
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
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 2000 total points
ID: 35495345
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Six Sigma Control Plans
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question