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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.