in reply to Re^4: Compiling C program with a Static Perl
in thread Compiling C program with a Static Perl

Thanks, it looks promising. If I understood correctly, I build a static perl with -Uusedl and my dependencies with -Dextras so that they're statically built also. I've just tried to put the YAML::XS module in-Dextras and it didn't build with some mysterious "Failed" CPAN message. So I stuck YAML::XS into the ext/ dir before building it and it worked...!

...well, apparently. I'm still getting this error when I test to see if my new static Perl has the module linked to it:

perl -MYAML::XS -E '' Can't load module YAML::XS::LibYAML, dynamic loading not available in +this perl. (You may need to build a new perl executable which either supports dynamic loading or has the YAML::XS::LibYAML module statically linke +d into it.) at localperl/lib/5.24.2/YAML/XS.pm line 20.

...but I'm pretty sure I saw LibYAML being compiled during make (I did make LINKTYPE=static actually). Why is my static perl trying to Dynaload the module??

Replies are listed 'Best First'.
Re^6: Compiling C program with a Static Perl
by syphilis (Archbishop) on Sep 04, 2017 at 01:57 UTC
    I did make LINKTYPE=static actually

    I believe you should run perl Makefile.PL LINKTYPE=static and follow that with a plain make command. See the ExtUtils::MakeMaker documentation

    Cheers,
    Rob
      There was no Makefile.PL, I'm referring to the Perl source make, the one that comes after Configure.
        I'm referring to the Perl source make

        Aaah ... however, I don't think the LINKTYPE=static argument does anything.

        It's a long time since I've built perl statically, and I'm a bit hazy on the details. So I just tried a build of 5.26.0 configured with '-des -Uusedl -Dprefix=/home/me/perl526-static'.
        However, that fails at the 'make' stage with:
        libperl.a(regexec.o): In function `Perl__is_grapheme': regexec.c:(.text+0x12b70): multiple definition of `Perl__is_grapheme' lib/auto/re/re.a(re_exec.o):re_exec.c:(.text+0x1c020): first defined h +ere collect2: error: ld returned 1 exit status makefile:369: recipe for target 'perl' failed make: *** [perl] Error 1
        Have I missed something in my Configure args ? (Running 'make LINKTYPE=static' makes no difference.)
        What is your 'perl -V' output ?
        When I finish writing this, I'll try current blead - and send a post to p5p if it also fails to build statically.

        Having had a read through the INSTALL file, it seems to me that what you've done should have worked ... but clearly hasn't wrt YAML::XS.
        Do any of the other ext modules throw the same error when you try to load them ?
        Try re-building YAML::XS from *fresh* source with:
        perl Makefile.PL LINKTYPE=static make perl -Mblib -MYAML::XS -E 1
        Does that last command then run without error ?

        UPDATE: Building perl statically from current git source (commit 97fcda7...) works fine for me, with all tests passing. For some reason 'make test' doesn't run the ext/YAML-LibYAML test suite
        And I get the same results as rodd.
        It makes no difference to the error whether YAML::XS is built with perl (in the ext directory) or built separately after the static perl has been built and installed.
        I'm thinking that there's a bug in the way that YAML::XS is being dealt with. The INSTALL file does state this:

        <quote>
        If you unpack any additional extensions in the ext/ directory before running Configure, then Configure will offer to build those additional extensions as well. Most users probably shouldn't have to do this -- it is usually easier to build additional extensions later after perl has been installed. However, if you wish to have those additional extensions statically linked into the perl binary, then this offers a convenient way to do that in one step.
        </quote>

        UPDATE 2: There's a bit more to it than I expected. I was able to get a loadable YAML::XS installed as per follows:
        cd YAML-LibYAML-0.65 perl Makefile.PL make perl make -f Makefile.aperl inst_perl MAP_TARGET=perl make -f Makefile.aperl map_clean

        Cheers,
        Rob