Richard Chen wrote:
> Hi,
> I am using Inline to integrate a C shared library.
> Everthing works fine if I set LD_LIBRARY_PATH correctly
> in my shell first and then start the perl program. But I would
> really like to set this variable inside the perl program
> itself so that the program will work whether
> LD_LIBRARY_PATH is set in the parent shell environment or not.
> I thought that by adding this to the top of the perl script
>
> BEGIN {
> $ENV{LD_LIBRARY_PATH}="/path/to/lib";
> }
>
> would work. But it does not:
>
> $ ./foo.pl
> Had problems bootstrapping Inline module 'foo_pl_067f'
>
> Can't load '/site1/www.clinique.com/tmp/_Inline/lib/auto/foo_pl_067f/foo_pl_067f.so'
>for module foo_pl_067f: ld.so.1: /usr/bin/perl: fatal: foo.so: open failed: No such
>file or directory at /usr/local/lib/perl5/5.00503/sun4-solaris/DynaLoader.pm line 169.
>
> at /usr/local/lib/perl5/site_perl/5.005/Inline.pm line 432
>
> at ./foo.pl line 60
> BEGIN failed--compilation aborted at ./foo.pl line 60.
>
> It looks like the Inline part is not a subprocess of the perl
> script so that the setting in perl script does not affect how
> Inline part works. Is there a way to change this?
>
> My main question is:
> Is there a way to set LD_LIBRARY_PATH in the perl script
> when using Inline to interface a C shared library?
>
Don't think so. The LD_LIBRARY_PATH is used by the operating system to
marshall up the libraries when the program starts. Dynamic loading may
allow you to not have to bring libraries into memory until you need
them, but the relationships have to be figured out before the program
starts, I think.
If this were 'C', there might be system calls you could use to
accomplish this but I think you are SOL in Perl. Can someone show me I'm
wrong?
But what's the big deal? Put the LD_LIBRARY_PATH statement into
/etc/profile and move on, if you are the sysadmin.
If not,
$vi foo
i
#!/bin/ksh
export LD_LIBRARY_PATH=yadayadayada
perl foo.pl
<ESC>:wq
--
Matthew O. Persico
New York City - United We Stand