I have a Perl script similar to
my $relSourcePath;
my $inlineCFile;
my $inlineBuildDir;
my $libDir;
my $incDir;
BEGIN {
# this file is in the same directory as the rest of the sources
$relSourcePath = File::Spec->rel2abs(dirname($0));
die "Install path must not have spaces.\n" if $relSourcePath =~ /\
+s/;
# Need to build the path to the Inline C file here, so that we cou
+ld
# reference it below
my @dirs = ();
push @dirs, $relSourcePath;
$inlineCFile = File::Spec->catfile(@dirs, "my_wrapper.c");
push @dirs, ".Inline";
$inlineBuildDir = File::Spec->catdir(@dirs);
pop @dirs;
push @dirs, "lib";
$libDir = File::Spec->catdir(@dirs);
pop @dirs;
push @dirs, "include";
$incDir = File::Spec->catdir(@dirs);
}
use Inline (
C => Config =>
LIBS => "-L$libDir -lmylib",
INC => "-I$incDir",
DIRECTORY => $inlineBuildDir,
);
# this is the C source file for interfacing to the library. Yes, this
+could be
# done natively in Perl, but this is just as easy (and probably faster
+ to
# execute).
use Inline C => "$inlineCFile";
$ENV{MYVAR} = "my_var_value";
print "ENV{MYVAR} = '" . qqq("MYVAR") . "'\n";
The
my_wrapper.c file is basically a wrapper to glue together
mylib with Perl code. As a test, I added a function qqq to
my_wrapper.c as follows:
char * qqq(const char *envName)
{
return getenv(envName);
}
When I run the Perl script, I see that Perl does indeed set the environment variable so that the qqq() function can extract its value. However, it appears that the value of the environment variable is not the same when executing code within
mylib. It's as though,
mylib was loaded into a different memory space
Is there anything I can do in Perl to set the environment variable so that it's visible to mylib?
P.S. As a sanity test, I set the environment variable on the command line first and then ran my test. The value used by mylib is the one that was set on the command line and not the one from within Perl.