I'm running into some of the same problems outlined in PATH is not setting - PERL and DBI, DBD::Oracle and LD_LIBRARY_PATH (problem summary: LD_LIBRARY_PATH and sometimes other environment variables need to be set/unset to certain values before the program starts in order to run correctly), so here is my solution to it. Comments welcome... package FixInit;
sub import {
return if $ENV{FIXINIT_PM};
my $class = shift;
my @chk = $^C ? '-c' : ();
$ENV{FIXINIT_PM} = 1;
my @path;
while ( my $dir = shift @_ ) {
last if $dir eq "--";
push @path, $dir;
}
$ENV{LD_LIBRARY_PATH} = join ":", @path;
my %env = @_;
$ENV{keys %env} = values %env;
exec $^X => @chk, $0, @ARGV;
die "Could not exec $^X $0: $!";
}
1;
__END__
=head1 NAME
FixInit - Fix library path and ENV variables and restart program
=head1 SYNOPSIS
# Before all other use statements
use FixInit;
# or
use FixInit qw(libpath1 libpath2 -- env1 value1 env2 value2);
=head1 DESCRIPTION
LD_LIBRARY_PATH interferes with the path used when some libraries
were compiled. It should only be used as a last resort.
Setting LD_LIBRARY_PATH at runtime does no good, as it is already
cached by the linker, so we set it, and restart the program with
the original arguments.
This library should be used before any other libraries to make sure
it works correctly.
An alternative would be to reset LD_LIBRARY_PATH and any environment
variables in a shell wrapper, and then run your program from the wrapp
+er.
=cut
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|