1

I'm trying to install XML::Simple under Perlbrew but am hitting an error that seems like it requires root access to fix. However, the whole purpose of using perlbrew (or one of them, at least) is to disassociate your perl environment from the OS installed perl version.

I've installed perlbrew (5.10.1, legacy code requirement) and several modules. It is currently functioning as expected. However, I get an error when trying to install XML::Simple.

$ cpanm XML::Simple
--> Working on XML::Simple
Fetching http://www.cpan.org/authors/id/G/GR/GRANTM/XML-Simple-2.25.tar.gz ... OK
Configuring XML-Simple-2.25 ... OK
==> Found dependencies: XML::SAX::Expat
--> Working on XML::SAX::Expat
Fetching http://www.cpan.org/authors/id/B/BJ/BJOERN/XML-SAX-Expat-0.51.tar.gz ... OK
Configuring XML-SAX-Expat-0.51 ... OK
==> Found dependencies: XML::Parser
--> Working on XML::Parser
Fetching http://www.cpan.org/authors/id/T/TO/TODDR/XML-Parser-2.44.tar.gz ... OK
Configuring XML-Parser-2.44 ... OK
Building and testing XML-Parser-2.44 ... FAIL
! Installing XML::Parser failed. See /home/user1/.cpanm/work/1532923694.18203/build.log for details. Retry with --force to force install it.
! Installing the dependencies failed: Module 'XML::Parser' is not installed
! Bailing out the installation for XML-SAX-Expat-0.51.
! Installing the dependencies failed: Module 'XML::SAX::Expat' is not installed
! Bailing out the installation for XML-Simple-2.25.
$

Here's the output of the log file (cut down to the pertinent part):

cp Expat.pm ../blib/lib/XML/Parser/Expat.pm
Running Mkbootstrap for Expat ()
chmod 644 "Expat.bs"
"/home/user1/perl5/perlbrew/perls/perl-5.10.1/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Expat.bs ../blib/arch/auto/XML/Parser/Expat/Expat.bs 644
"/home/user1/perl5/perlbrew/perls/perl-5.10.1/bin/perl" "/home/user1/perl5/perlbrew/perls/perl-5.10.1/lib/5.10.1/ExtUtils/xsubpp" -noprototypes -typemap '/home/user1/perl5/perlbrew/perls/perl-5.10.1/lib/5.10.1/ExtUtils/typemap' -typemap /home/user1/.cpanm/work/1532923694.18203/XML-Parser-2.44/Expat/typemap'  Expat.xs > Expat.xsc
mv Expat.xsc Expat.c
cc -c   -m32 -march=i686 -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2   -DVERSION=\"2.44\" -DXS_VERSION=\"2.44\" -fPIC "-I/home/user1/perl5/perlbrew/perls/perl-5.10.1/lib/5.10.1/x86_64-linux/CORE"   Expat.c
Expat.xs:12:19: fatal error: expat.h: No such file or directory
 #include <expat.h>
                   ^
compilation terminated.
make[1]: *** [Expat.o] Error 1
make[1]: Leaving directory `/home/user1/.cpanm/work/1532923694.18203/XML-Parser-2.44/Expat'
make: *** [subdirs] Error 2
-> FAIL Installing XML::Parser failed. See /home/user1/.cpanm/work/1532923694.18203/build.log for details. Retry with --force to force install it.
-> FAIL Installing the dependencies failed: Module 'XML::Parser' is not installed
-> FAIL Bailing out the installation for XML-SAX-Expat-0.51.
-> FAIL Installing the dependencies failed: Module 'XML::SAX::Expat' is not installed
-> FAIL Bailing out the installation for XML-Simple-2.25.
~

I have tried installing expat locally via:

wget https://sourceforge.net/projects/expat/files/expat/2.2.4/expat-2.2.4.tar.bz2
tar xjf expat-2.2.4.tar.bz2
cd expat-2.2.4
./configure --prefix=/home/user1/perl5/perlbrew/perls/perl-5.10.1/
make
make install

I've verified that expat.h is in ~/perl5/perlbrew/perls/perl-5.10.1/include. I updated my path to include that location.

Every fix I see is to install expat via the operating system tools (for the various flavors).

The issue is that I don't have root access and while I can technically ask the admin to install it, my project requires a solution that doesn't require root access as it will be copied through multiple environments and servers.

Is there a way to install XML::Simple without expat? Or a way to install expat in perlbrew such that XML::Simple will find it and use it?

melpomene
  • 84,125
  • 8
  • 85
  • 148
iolympian
  • 469
  • 1
  • 4
  • 19
  • https://stackoverflow.com/a/15504710/1848654? – melpomene Jul 30 '18 at 04:31
  • I tried that, but that solution didn't work for me. I have XML::SAX installed and still get the error. $ cpanm XML::SAX XML::SAX is up to date. (1.00) $ cpanm XML::Simple Installing XML::Parser failed. See /home/user1/.cpanm/work/1532925534.21007/build.log for details. Retry with --force to force install it. ! Installing the dependencies failed: Module 'XML::Parser' is not installed ! Bailing out the installation for XML-SAX-Expat-0.51. ! Installing the dependencies failed: Module 'XML::SAX::Expat' is not installed ! Bailing out the installation for XML-Simple-2.25. – iolympian Jul 30 '18 at 04:39
  • To install XML::Parser, you need the expat library installed, as well as the header files for the expat library – ikegami Jul 30 '18 at 04:42
  • There are environment variables both for header files and the runtime linker (for `.so` files), but I forget what they're called. – melpomene Jul 30 '18 at 05:04
  • `./configure --prefix=/home/user1` would make far more sense than `./configure --prefix=/home/user1/perl5/perlbrew/perls/perl-5.10.1/`. It seems you simply forgot to tell programs where to look. For `gcc`, [it looks like](https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html) env var `CPATH` can be used to specify the include dir, and env var `LIBRARY_PATH` can be used to specify the library dir. – ikegami Jul 30 '18 at 05:04
  • Possible duplicate of [Installing XML::Parser requires expat.h](https://stackoverflow.com/questions/15484620/installing-xmlparser-requires-expat-h) – el.pescado - нет войне Jul 30 '18 at 06:28
  • 2
    Do you really want to install XML::Simple? It's really not as simple as its name might imply and even the documentation [discourages its use](https://metacpan.org/pod/XML::Simple#STATUS-OF-THIS-MODULE). – Dave Cross Jul 30 '18 at 08:38
  • 1
    @Dave: Indeed. `XML::Simplistic` or `XML::Naive` might be more appropriate! – Borodin Jul 30 '18 at 10:40
  • Unfortunately, it's out of current scope to change the library. Within scope in 2 weeks, but out of scope for the server install of the code base. – iolympian Aug 01 '18 at 18:39

1 Answers1

3

Install XML::Parser manually and tell ExtUtils::MakeMaker where to find the C libraries. See INC and LIBS.

cpanm --look XML::Parser
PERLPREFIX=/home/user1/perl5/perlbrew/perls/perl-5.10.1/
perl Makefile.PL INC=-I$PERLPREFIX/include LIBS=-L$PERLPREFIX/lib
make && make test && make install

If you use cpan instead of cpanm, you can make this hands-off and permanent. Set the option makepl_arg, e.g. by running at the CPAN shell prompt):

o conf makepl_arg "INC=-I/home/user1/perl5/perlbrew/perls/perl-5.10.1/include LIBS=-L/home/user1/perl5/perlbrew/perls/perl-5.10.1/lib"
o conf commit

P.S. expat 2.2.5 is out

daxim
  • 39,270
  • 4
  • 65
  • 132