I have used Super Search to find an answer to this, but haven't found the right answer yet:

I have a Perl script that needs to load a module, foo.pm, which in turn uses XSLoader to load libfoo_perl.so. libfoo_perl.so has a reference to bar.so which is not in a standard path. I can not modify the environment variables before running my script. The script looks like this:

$ENV{PATH} = "/foo/bin:/bar/bin:$ENV{PATH}"; $ENV{LD_LIBRARY_PATH} = "/foo/bin:/bar/bin:$ENV{LD_LIBRARY_PATH}"; $ENV{PERL5LIB} = "/foo/lib:$ENV{PERL5LIB}"; use lib "/foo/lib"; use foo; # if I comment the above line and # uncomment below, it works, but that is not what I want. # print `perl -e 'use foo; print "success\n";'`;
The above would give me an error like this: Can't load '/foo/bin/libfoo_perl.so' for module foo_perl: bar.so: cannot open shared object file: No such file or directory at /auto/perl/5.8.3/lib/5.8.3/i686-linux-thread-multi/DynaLoader.pm line 229.

I know the easy solution is to add the directory for bar.so to LD_LIBRARY_PATH, but I can not do that. I am not allowed to touch the environment outside the script. Only inside the script. And no, I can not recompile libfoo_perl.so to hard code the path to bar.so.

It would appear that the dl_load_file() function in DynaLoader does not inherit the current %ENV settings, and instead uses the parent environment settings.

Using Perl 5.8.3, if you haven't guessed already.

Thanks for the help,
Imran


In reply to DynaLoader and LD_LIBRARY_PATH by CountOrlok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.