How do I build 32-bit XS modules for a 32-bit custom Perl on a 64-bit CentOS system?
Asked Answered
A

2

6

I have a 64-bit CentOS 6 system running a custom-built version of Perl 5.12.5, that is build for 32-bits. (Alas, this is because we are using the same RPMs for 32-bit and 64-bit systems.)

When I build XS modules (e.g. JSON::XS) on the server, it fails because it's building 64-bit libraries. I get an error like

Can't load '.cpanm/work/1370279501.28897/JSON-XS-2.33/blib/arch
/auto/JSON/XS/XS.so' for module JSON::XS: .cpanm/work/137027950
1.28897/JSON-XS-2.33/blib/arch/auto/JSON/XS/XS.so: wrong ELF class: ELFCLASS64
at /opt/perl/lib/5.12.5/i686-linux/DynaLoader.pm line 200.

I've tried setting the CFLAGS variable to "-m32-bit" but it does not work.

What do I need to do to compile XS modules properly? Ideally, I'd like something that works with cpanminus but can use cpan or cpanplus if need be.

Antisyphilitic answered 3/6, 2013 at 17:33 Comment(11)
Odd. It should use the exact same settings that were used to build Perl.Nystatin
@Nystatin The Perl was build on a 32-bit machine, so perhaps the settings didn't need to be made explicit.Antisyphilitic
Fix your broken Perl (i.e. install it properly) to solve your problem.Nystatin
@Nystatin Can you be more specific? How is it not installed properly? It's in the PATH, the PERL5LIB variable is set correctly, as are local-lib variables set properly. The CPAN and CPANPLUS modules are properly configured and worked fine on the 32-bit system.Antisyphilitic
You said you built it on a different machine than the one on which it's installed, yet perl doesn't currently have a cross-compiler.Nystatin
@Nystatin So what is broken about the Perl? What do I need to do to fix it?Antisyphilitic
The fact that you can't install modules. Install it properly. Installation instructions are quite simple, and are found in the INSTALL file. But you already know that if you've built a custom Perl!?Nystatin
The version of Perl is installed properly. From what I gather, it may not have been compiled properly.Antisyphilitic
You already admitted you didn't install it properly. There's no indication it wasn't compiled properly. What game are you playing???Nystatin
In what way did I admit that it wasn't installed properly?Antisyphilitic
Already asked and answered. You said you built it on a different machine than the one on which it's installed.Nystatin
I
2

Perl's build system (in particular, ExtUtils::MakeMaker and ExtUtils::CBuilder) assumes the compilation platform that was used to build that perl is also usable runtime platform. Evidently that's not the case here.

The obvious solution is to compile perl with options that would result in the same executables on both toolchains. This is rather tricky.

Intussuscept answered 5/6, 2013 at 9:59 Comment(1)
Any idea what those options would be?Antisyphilitic
N
1

Turns out this answer works for me:

wwalker $ PERL_MM_OPT='CCFLAGS="-m32 -march=i686" LDDLFLAGS="-m32 -march=i686"' /opt/depot/perl-5.8.5/bin/perl -MCPAN -e shell

cpan shell -- CPAN exploration and modules installation (v1.7601)
ReadLine support enabled

cpan> install DBIx::Class
Northeaster answered 21/12, 2015 at 0:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.