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

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

Replies are listed 'Best First'.
Re^7: Compiling C program with a Static Perl
by rodd (Scribe) on Sep 04, 2017 at 07:14 UTC
    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