How to create 32-bit XS modules for 32-bit custom Perl on a 64-bit CentOS system?

I have a 64-bit CentOS 6 system on which a custom version of Perl 5.12.5 is installed, which is built for 32-bit. (Alas, this is because we use 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 creates 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 tried to set the CFLAGS variable to "-m32-bit", but it does not work.

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

+6
source share
2 answers

The Perl build system (in particular, ExtUtils :: MakeMaker and ExtUtils :: CBuilder) assumes a compilation platform that was used to build, which perl is also used by the runtime platform. Obviously, this is not the case here.

The obvious solution is to compile perl with parameters that will lead to the same executables on both toolchains. This is pretty tricky.

+2
source

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 
0
source

Source: https://habr.com/ru/post/946431/


All Articles