Source Allies Logo

Sharing Our Passion for Technology

& Continuous Learning

<   Back to Blog

Building Perl modules on OpenSolaris

Anyone that's worked with Perl is probably familiar with CPAN.pm. CPAN.pm is the bundled module that handles downloading and installing modules from the CPAN repository. It usually works flawlessly but I've noticed that on OpenSolaris the process can be a bit more spotty.

Let's try installing Mason as an example:

perl -MCPAN -e "install HTML::Mason"

Generally the first thing I notice is that all (or a large number) of the tests are failing. For example here is the output of one of the tests:

t/20-plugins.......................Can't locate HTML/Entities.pm in @INC (@INC
 contains: /root/.cpan/build/HTML-Mason-1.42/blib/lib /root/.cpan/build/H
TML-Mason-1.42/blib/arch t/lib inc /usr/perl5/5.8.4/lib/i86pc-solaris-64int
 /usr/perl5/5.8.4/lib/i86pc-solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_
perl/5.8.4/i86pc-solaris-64int /usr/perl5/site_perl/5.8.4/i86pc-solaris-64int
 /usr/perl5/site_perl/5.8.4 /usr/perl5/site_perl/5.8.4/i86pc-solaris-64int /u
sr/perl5/site_perl/5.8.4 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.8.4/i8
6pc-solaris-64int /usr/perl5/vendor_perl/5.8.4/i86pc-solaris-64int /usr/per
l5/vendor_perl/5.8.4 /usr/perl5/vendor_perl/5.8.4/i86pc-solaris-64int /usr
/perl5/vendor_perl/5.8.4 /usr/perl5/vendor_perl . /usr/perl5/5.8.4/lib/i86pc
-solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_perl/5.8.4/i86pc-solaris-6
4int /usr/perl5/site_perl/5.8.4 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.
8.4/i86pc-solaris-64int /usr/perl5/vendor_perl/5.8.4 /usr/perl5/vendor_perl
.) at /root/.cpan/build/HTML-Mason-1.42/blib/lib/HTML/Mason/Escapes.pm
 line 14.

Hmm, because we're not installing HTML::Entities this means that it should have been brought in when CPAN.pm was building the dependencies. I trust CPAN.pm got this right, if for no other reason than that I remember it prompting to install that module. After digging around in the sea of output eventually I find that installing Digest::SHA1 failed because of this error:

cc -c   -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_TS_ERRNO -xO3 -xspace -xildoff   -DVERSION=\"2.12\" -DXS_VERSION=\"2.12\" -KPIC "-I/usr/perl5/5.8.4/lib/i86pc-solaris-64int/CORE"   SHA1.c
cc: unrecognized option `-KPIC'
cc: language ildoff not recognized
cc: SHA1.c: linker input file unused because linking not done

Our C compiler isn't happy with how it's being called. Now we need to find out which compiler we're using:

 bash-3.2$ which cc
/usr/gnu/bin/cc

While the GCC compiler is a fine fine compiler, the way CPAN.pm tries to build things on OpenSolaris involves params that only SunStudio understands. At this point there are two options. We can either patch the generated Makefile so that it doesn't include stuff GCC can't understand or we can switch the compiler to SunStudio. I prefer the latter because it is easiest:

pkg install sunstudio  # Install it if not already done
export PATH="/opt/SUNWspro/bin:$PATH" # Put it first on the path

Now that we're using the correct compiler the build goes slightly less awful. We get a new error.

/usr/bin/perl "-Iblib/arch" "-Iblib/lib" Build.PL Build
Too early to specify a build action 'Build'.  Do 'Build Build' instead.

This is caused by the ExtUtils::MakeMaker module not being installed. I don't know how my system got into such a state, but it is easy enough to fix:

perl -MCPAN -e "install 'ExtUtils::MakeMaker' "

Let's try one more time:

perl -MCPAN -e "install HTML::Mason"
...Huge Snip...
 /usr/gnu/bin/make install  -- OK

Success!