Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

perl

xs

makemaker

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.

like image 890
Rob Avatar asked Jun 03 '13 17:06

Rob


People also ask

Is GCC 32 or 64 bit?

Mostly compiler(gcc or clang) of C and C++, nowadays come with default 64-bit version.


1 Answers

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.

like image 163
Leon Timmermans Avatar answered Sep 30 '22 14:09

Leon Timmermans