PERL5LIB variable does not work as expected

I

Ishmael

I am trying to get Perl to recognize a module (Math::GMP) that is
installed in a local directory, i.e. not the same directory as the rest
of Perl. I've been trying to use the PERL5LIB environment variable to
get Perl to search on the correct path, but it doesn't work. Here's
what I mean:


First I set (what I believe to be) the search path:

setenv PERL5LIB
/home/kstahl/PERL/Digest-1.15:/home/kstahl/PERL/Digest-SHA1-2.11:
/home/kstahl/PERL/Scalar-List-Utils-1.19:/home/kstahl/PERL/gmp-4.2.1:
/home/kstahl/PERL/Math-GMP-2.04:/home/kstahl/PERL/Math-GMP-2.04/lib:
/home/kstahl/PERL/Math-GMP-2.04/blib:
/home/kstahl/PERL/Math-GMP-2.04/lib/site_perl/5.6.1/sol2.sun4/auto/Math/GMP:
/home/kstahl/PERL/Net-SSH-Perl-1.30


Now I check to see if it finds the module.

perl -MMath::GMP -e 'print "ok\n"'


Answer: Nope, it's still looking in the perl installation directory.

Can't load
'/apps/gnu/perl_local/lib/site_perl/5.6.1/sol2.sun4/auto/Math/GMP/GMP.so'
for
module Math::GMP: ld.so.1: perl: fatal: libgmp.so.3: open failed: No
such file
or directory at /apps/gnu/perl-5.6.1/lib/sol2.sun4/DynaLoader.pm line
206.
at -e line 0
Compilation failed in require.
BEGIN failed--compilation aborted.


Check to make sure correct directory is on the path:

perl -e 'while(<@INC>) { print "$_\n"; }'

/home/kstahl/PERL/Digest-1.15
/home/kstahl/PERL/Digest-SHA1-2.11
/home/kstahl/PERL/Scalar-List-Utils-1.19
/home/kstahl/PERL/gmp-4.2.1
/home/kstahl/PERL/Math-GMP-2.04
/home/kstahl/PERL/Math-GMP-2.04/lib/sol2.sun4
/home/kstahl/PERL/Math-GMP-2.04/lib
/home/kstahl/PERL/Math-GMP-2.04/blib
/home/kstahl/PERL/Math-GMP-2.04/lib/site_perl/5.6.1/sol2.sun4/auto/Math/GMP
/home/kstahl/PERL/Net-SSH-Perl-1.30
/apps/gnu/perl-5.6.1/lib/sol2.sun4
/apps/gnu/perl-5.6.1/lib
/apps/gnu/perl_local/lib/site_perl/5.6.1/sol2.sun4
/apps/gnu/perl_local/lib/site_perl/5.6.1
/apps/gnu/perl_local/lib/site_perl
..


Looks to me like the every conceivable subdirectory is included (as
well as the complete path to the actual library, GMP.so). What am I
missing here?

Thanks a priori!
 
C

ced

Ishmael said:
I am trying to get Perl to recognize a module (Math::GMP) that is
installed in a local directory, i.e. not the same directory as the rest
of Perl. I've been trying to use the PERL5LIB environment variable to
get Perl to search on the correct path, but it doesn't work. Here's
what I mean:


First I set (what I believe to be) the search path:

setenv PERL5LIB
/home/kstahl/PERL/Digest-1.15:/home/kstahl/PERL/Digest-SHA1-2.11:
/home/kstahl/PERL/Scalar-List-Utils-1.19:/home/kstahl/PERL/gmp-4.2.1:
/home/kstahl/PERL/Math-GMP-2.04:/home/kstahl/PERL/Math-GMP-2.04/lib:
/home/kstahl/PERL/Math-GMP-2.04/blib:
/home/kstahl/PERL/Math-GMP-2.04/lib/site_perl/5.6.1/sol2.sun4/auto/Math/GMP:
/home/kstahl/PERL/Net-SSH-Perl-1.30


Now I check to see if it finds the module.

perl -MMath::GMP -e 'print "ok\n"'


Answer: Nope, it's still looking in the perl installation directory.

Can't load
'/apps/gnu/perl_local/lib/site_perl/5.6.1/sol2.sun4/auto/Math/GMP/GMP.so'
for
module Math::GMP: ld.so.1: perl: fatal: libgmp.so.3: open failed: No such file

^^^^^^^^^^^^^^^^^^^^^^^^

Are you sure the install completed successfully....? The message
indicates
the external gmp library (default install is /usr/local/lib) is
unavailable. Either
the library is missing or there are permission problems.
 
M

Mumia W. (on aioe)

I am trying to get Perl to recognize a module (Math::GMP) that is
installed in a local directory, i.e. not the same directory as the rest
of Perl. I've been trying to use the PERL5LIB environment variable to
get Perl to search on the correct path, but it doesn't work. Here's
what I mean:


First I set (what I believe to be) the search path:

setenv PERL5LIB
/home/kstahl/PERL/Digest-1.15:/home/kstahl/PERL/Digest-SHA1-2.11:
/home/kstahl/PERL/Scalar-List-Utils-1.19:/home/kstahl/PERL/gmp-4.2.1:
/home/kstahl/PERL/Math-GMP-2.04:/home/kstahl/PERL/Math-GMP-2.04/lib:
/home/kstahl/PERL/Math-GMP-2.04/blib:
/home/kstahl/PERL/Math-GMP-2.04/lib/site_perl/5.6.1/sol2.sun4/auto/Math/GMP:
/home/kstahl/PERL/Net-SSH-Perl-1.30


Now I check to see if it finds the module.

perl -MMath::GMP -e 'print "ok\n"'


Answer: Nope, it's still looking in the perl installation directory.

Can't load
'/apps/gnu/perl_local/lib/site_perl/5.6.1/sol2.sun4/auto/Math/GMP/GMP.so'
for
module Math::GMP: ld.so.1: perl: fatal: libgmp.so.3: open failed: No
such file
or directory at /apps/gnu/perl-5.6.1/lib/sol2.sun4/DynaLoader.pm line
206.
at -e line 0
Compilation failed in require.
BEGIN failed--compilation aborted.


Check to make sure correct directory is on the path:

perl -e 'while(<@INC>) { print "$_\n"; }'

/home/kstahl/PERL/Digest-1.15
/home/kstahl/PERL/Digest-SHA1-2.11
/home/kstahl/PERL/Scalar-List-Utils-1.19
/home/kstahl/PERL/gmp-4.2.1
/home/kstahl/PERL/Math-GMP-2.04
/home/kstahl/PERL/Math-GMP-2.04/lib/sol2.sun4
/home/kstahl/PERL/Math-GMP-2.04/lib
/home/kstahl/PERL/Math-GMP-2.04/blib
/home/kstahl/PERL/Math-GMP-2.04/lib/site_perl/5.6.1/sol2.sun4/auto/Math/GMP
/home/kstahl/PERL/Net-SSH-Perl-1.30
/apps/gnu/perl-5.6.1/lib/sol2.sun4
/apps/gnu/perl-5.6.1/lib
/apps/gnu/perl_local/lib/site_perl/5.6.1/sol2.sun4
/apps/gnu/perl_local/lib/site_perl/5.6.1
/apps/gnu/perl_local/lib/site_perl
..


Looks to me like the every conceivable subdirectory is included (as
well as the complete path to the actual library, GMP.so). What am I
missing here?

Thanks a priori!

I don't think you installed Math::GMP right.

First, you would decide on a place to install Perl modules such as
/home/kstahl/perlinst/

After you've downloaded and unpacked the source package for Math::GMP,
you would go into the directory where the package was unpacked (e.g.
/home/kstahl/PERL/Math-GMP-2.04/) and do this:

perl Makefile.PL PREFIX=/home/kstahl/perlinst
make test && make install

That should install the module into /home/kstahl/perlinst.

Then, PERL5LIB might be set like so:
PERL5LIB=/home/kstahl/perlinst/share/perl:/home/kstahl/perlinst/share/lib

You definitely should not need to add a path to PERL5LIB for each module
installed.
 
I

Ishmael

I don't think you installed Math::GMP right.

That was my first thought too, but when I run 'make test', it tells me
'All tests successful', so I think it should be ok.

First, you would decide on a place to install Perl modules such as
/home/kstahl/perlinst/

I wasn't entirely clear about where I could install the modules, so I
(naively) installed each module into it's own directory (i.e. the same
directory the module was unpacked in). For example, to install GMP, I
ran 'perl Makefile.PL PREFIX=/home/kstahl/PERL/Math-GMP-2.04' )
Thinking this might be the problem, I just recompiled GMP in a separate
directory, as you suggest, but alas, even though 'make test' gives no
errors, perl refuses to search on the new path (which I added to the
PERL5LIB variable)
After you've downloaded and unpacked the source package for Math::GMP,
you would go into the directory where the package was unpacked (e.g.
/home/kstahl/PERL/Math-GMP-2.04/) and do this:

perl Makefile.PL PREFIX=/home/kstahl/perlinst
make test && make install

That should install the module into /home/kstahl/perlinst.

Then, PERL5LIB might be set like so:
PERL5LIB=/home/kstahl/perlinst/share/perl:/home/kstahl/perlinst/share/lib

You definitely should not need to add a path to PERL5LIB for each module
installed.

I noticed you used 'share/perl' and 'share/lib' as subdirectories above
- but I don't have those. I only have a lib/ and a man/ directory
under perlinst. Could this be the problem?
 
B

brian d foy

I don't think you installed Math::GMP right.

That was my first thought too, but when I run 'make test', it tells me
'All tests successful', so I think it should be ok.[/QUOTE]

That's just the tests. You still have to install it.

See the perlfaq answers returned from these queries with perldoc:

% perldoc -q install

% perldoc -q directory

Good luck!
 
D

DJ Stunks

Ishmael said:
I am trying to get Perl to recognize a module (Math::GMP) that is
installed in a local directory, i.e. not the same directory as the rest
of Perl. I've been trying to use the PERL5LIB environment variable to
get Perl to search on the correct path, but it doesn't work.

Others have addressed your actual problem, but my question is why use
PERL5LIB in your environment rather than the lib pragma in your script
(er, program? :p)

perldoc lib

-jp
 
I

Ishmael

DJ said:
Others have addressed your actual problem, but my question is why use
PERL5LIB in your environment rather than the lib pragma in your script
(er, program? :p)

perldoc lib

-jp

Thanks for the advice.

In answer to the two posts above,

a) I did install GMP, using 'make install'. No apparent problems.

b) Using the lib pragma also fails. I've written a simple test script
with these lines:

use lib "/home/kstahl/PERL/MODULE_INSTALL";
use Math::GMP;

I've also tried to add the full path to the actual GMP.so file, but no
matter what I do, I keep getting the same error:

Can't load
'/apps/gnu/perl_local/lib/site_perl/5.6.1/sol2.sun4/auto/Math/GMP/GMP.so'
for
module Math::GMP: ld.so.1: perl: fatal: libgmp.so.3: open failed: No
such file
or directory at /apps/gnu/perl-5.6.1/lib/sol2.sun4/DynaLoader.pm line
206.

Somehow, Perl is bypassing my @INC path. Now I've been reading a bit
about 'taint' mode, and it seems like that might be causing my
problems. Does anyone know how to turn taint mode off?
 
D

DJ Stunks

Jim said:
Because it is better to define a value in one place rather than in
every source file that needs it?

Yeah, I was just wondering. In my opinion, it seems like it would be
harder to get a consistent environment (CGI, cron, interactive shell vs
non-interactive shell) than it would be to add the pragma to those
files that needed it.

I also like that the location of the file is "documented" in the
source, rather than relying on external "magic".

But I guess that's why they make chocolate and vanilla :p

-jp
 
C

ced

Ishmael said:
a) I did install GMP, using 'make install'. No apparent problems.

b) Using the lib pragma also fails. I've written a simple test script
with these lines:

use lib "/home/kstahl/PERL/MODULE_INSTALL";
use Math::GMP;

I've also tried to add the full path to the actual GMP.so file, but no
matter what I do, I keep getting the same error:

Can't load
'/apps/gnu/perl_local/lib/site_perl/5.6.1/sol2.sun4/auto/Math/GMP/GMP.so'
for
module Math::GMP: ld.so.1: perl: fatal: libgmp.so.3: open failed: No
such file
or directory at /apps/gnu/perl-5.6.1/lib/sol2.sun4/DynaLoader.pm line
206.

Somehow, Perl is bypassing my @INC path. Now I've been reading a bit
about 'taint' mode, and it seems like that might be causing my
problems. Does anyone know how to turn taint mode off?

Wrong direction...

The error is "libgmp.so.3: open failed" which is the external library
dependency
for Math::GMP. It's installed separately -- this aspect of the problem
has nothing to do with @INC.

Normally, Perl looks at the libpth setting for external libraries.
Check
perl -V:libpth. Is libgmp.so.3 in one of those directories....? Is the
full
path to that library readable...? Where did you build and install
libgmp...?

--
Charles DeRykus


libraries
is that installed.
 
B

brian d foy

Jim Gibson said:
Because it is better to define a value in one place rather than in
every source file that needs it?

Well, PERL5LIB doesn't work under taint checking, for instance, but
lib always does.
 
I

Ishmael

Wrong direction...

The error is "libgmp.so.3: open failed" which is the external library
dependency
for Math::GMP. It's installed separately -- this aspect of the problem
has nothing to do with @INC.

Normally, Perl looks at the libpth setting for external libraries.
Check
perl -V:libpth. Is libgmp.so.3 in one of those directories....? Is the
full
path to that library readable...? Where did you build and install
libgmp...?


Ah! This is promising. I did as you said, and sure enough, the
library path came up as follows:

libpth='/usr/local/lib/db3 /usr/local/lib /apps/supported/lib/sol2.sun4
/usr/lib
/usr/ccs/lib';

Now the question is, how do I change the libpth? It doesn't appear to
be an environment variable.
 
C

ced

Ishmael said:
Ah! This is promising. I did as you said, and sure enough, the
library path came up as follows:

libpth='/usr/local/lib/db3 /usr/local/lib /apps/supported/lib/sol2.sun4
/usr/lib
/usr/ccs/lib';

Now the question is, how do I change the libpth? It doesn't appear to
be an environment variable.

No, it's a compile time setting when Perl is build. You may be able to
add something like this to the Math::GMP's Makefile.PL in the source
distro;

...
INC => '-I/path/to/some/library/include', # path to source include
where gmp.h is
LIBS => '-L/path/to/some/library/lib -lgmp', # path to source lib
where gmp.so is

This worked for me...
 
I

Ishmael

Just in case anyone reads this post in the future, I finally got the
PERL5LIB variable to work, simply by finding the correct local path to
add. For me, it was:

PATH_TO_MODULE_INSTALLATION_DIR/lib/site_perl

Note that the following DO NOT work:

PATH_TO_MODULE_INSTALLATION_DIR
PATH_TO_MODULE_INSTALLATION_DIR/lib

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top