rkg has asked for the wisdom of the Perl Monks concerning the following question:

Hi -- Pardon a newbie mod_perl question. When I run this simple test program
use Apache::Constants; print OK, "\n";
I get this error
Undefined subroutine &Apache::Constants::OK called at test.pl line 1.
Here's my @INC:
perl -e'print join("\n", @INC)' /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0
The perl is 5.8:
perl -v This is perl, v5.8.0 built for i386-linux-thread-multi (with 1 registered patch, see perl -V for more detail)
Any help most welcome --


Replies are listed 'Best First'.
Re: newbie mod_perl: @INC and Apache::Constants
by perrin (Chancellor) on Jul 31, 2003 at 17:47 UTC
    You can only call Apache::* modules from mod_perl. They don't work on the command line.
Re: newbie mod_perl: @INC and Apache::Constants
by dga (Hermit) on Jul 31, 2003 at 17:54 UTC

    Try adding a use lib to the directory which contains the Apache directory (where the mod_perl stuff lives):

    # in the shell: locate Apache/Constants.pm #then in your perl file use lib '/directory/path/to/directory/above/Apache';
by rkg (Hermit) on Jul 31, 2003 at 17:40 UTC
    Correction: This is the code I was testing
    use Apache::Constants qw(OK); print OK, "\n";
    I still get the same error...
Re: newbie mod_perl: @INC and Apache::Constants
by mod_alex (Beadle) on Aug 01, 2003 at 08:27 UTC
    Such a situation is possible because installation paths for perl modules can be a little bit mixed.
    To example you have perl binary from rpm, then you decided to reinstall CPAN module from from its original source, then it's possible that further modules you are installing is copied in the little bit different paths then perl contains in @INC variable.

    At least I saw this situation on my computer, when I tried to use existing perl from rpm and install mod_perl by manlually compiling its source. I would suggest you to reinstall perl, then apache, then mod_perl. I that case everything will be work fine for sure
still stuck...
by rkg (Hermit) on Jul 31, 2003 at 18:10 UTC
    Me again. Here's the modperl error on httpd start:
    root@sam:/home/xxxx/yyyy.com/mod-perl> start-dms [Thu Jul 31 02:04:00 2003] [error] Can't locate loadable object for mo +dule Apache::Constants in @INC (@INC contains: /home/xxxx/yyyy.com/mo +d-perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5. +8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/p +erl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_p +erl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /u +sr/lib/perl5/vendor_perl .) at /usr/lib/perl5/site_perl/5.8.0/i386-li +nux-thread-multi/mod_perl.pm line 14!Compilation failed in require at + /home/xxxx/yyyy.com/mod-perl/RKG/Redirect.pm line 5.!BEGIN failed--c +ompilation aborted at /home/xxxx/yyyy.com/mod-perl/RKG/Redirect.pm li +ne 5.!Compilation failed in require at (eval 2) line 3.! [Thu Jul 31 02:04:00 2003] [error] Can't load Perl module RKG::Redirec +t for server, exiting...!
    Here's my startup.pl
    root@sam:/home/xxxx/yyyy.com/mod-perl> cat startup.pl use strict; use lib qw(/home/xxxx/yyyy.com/mod-perl); 1; root@sam:/home/xxxx/yyyy.com/mod-perl>
    Here's my httpd.conf
    root@sam:/home/xxxx/yyyy.com> tail httpd.conf # End of proxy directives. PerlRequire /home/xxxx/yyyy.com/mod-perl/startup.pl PerlModule RKG::Redirect <Location /r> SetHandler perl-script PerlHandler Apache::Redirect </Location>
    Still stuck, thanks, folks!

      Can't locate loadable object for module Apache::Constants in @INC

      Did you follow the normal automated installation procedure (ie, using CPAN, PPM, or make install) to install Apache::Constants?

      I normally see this error when the .pm files are being found, but the relevant .so libraries were not built or installed correctly.

        Yes, I did. I've rebuilt both Apache and mod-perl since, and still getting the error. Stumped.