http://www.perlmonks.org?node_id=1233043

tinita has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to seperate some *.c/*.h files in YAML::XS. Currently the CPAN distribution looks like this: https://metacpan.org/source/TINITA/YAML-LibYAML-0.77

In the LibYAML directory there are copied files from the libyaml sources plus the bindings to perl (perl_libyaml.{c,h}).
I'd like to separate the libyaml sources into their own directories to make it easy to remove/ignore them and use the installed system libyaml instead, if one wants to.
Here I put the files into LibYAML/src and LibYAML/include: https://github.com/ingydotnet/yaml-libyaml-pm/tree/seperate-libyaml-source/YAML-LibYAML-0.77
The problem is I don't know how to change LibYAML/Makefile.PL.
Currently I'm getting this error because apparently it can't find the yaml.h:

Can't load '.../yaml-libyaml-pm/YAML-LibYAML-0.77/blib/arch/auto/YAML/ +XS/LibYAML/LibYAML.so' for module YAML::XS::LibYAML: .../yaml-libyaml-pm/YAML-LibYAML-0.77/blib/ +arch/auto/YAML/XS/LibYAML/LibYAML.so: undefined symbol: yaml_sequence_start_event_initialize at .../perl-5.24.1/lib/5.24.1/x86 +_64-linux/DynaLoader.pm line 193, <CONFIG> line 1. at .../yaml-libyaml-pm/YAML-LibYAML-0.77/blib/lib/YAML/XS.pm line 20.
Any ideas/pointers on how to set this up?

To reproduce:
Clone the git repo:
git clone https://github.com/ingydotnet/yaml-libyaml-pm -b seperate-libyaml-source
and go into the directory YAML-LibYAML-0.77:
perl Makefile.PL make make test


edit:
Tux was working on it and came up with this:

use ExtUtils::MakeMaker; use strict; use Config; my $s = join " " => sort glob ("*.c"), glob ("src/*.c"), glob ("*.xs" +); (my $o = $s) =~ s{\.(?:c|xs)\b}{$Config::Config{_o}}g; (my $l = $o) =~ s{\bsrc/}{}g; my $DEFINE = $^O eq 'MSWin32' ? '-DHAVE_CONFIG_H -DYAML_DECLARE_EXPORT' : '-DHAVE_CONFIG_H'; WriteMakefile( NAME => 'YAML::XS::LibYAML', ABSTRACT_FROM => 'lib/YAML/XS/LibYAML.pm', AUTHOR => 'Ingy döt Net <ingy@cpan.org>', PREREQ_PM => {}, CCFLAGS => "-I. -Isrc -Iinclude $DEFINE", OBJECT => $o, LDFROM => $l, );

It's working for me, thanks Tux!
The only weird thing is that it is compiling again whenever one does make test. Does anyone have an idea?

Replies are listed 'Best First'.
Re: Separating source files in YAML::XS
by marto (Cardinal) on Apr 27, 2019 at 20:38 UTC

    Following your instructions I get:

    ./perl_libyaml.h:16:10: fatal error: yaml.h: No such file or directory #include <yaml.h> ^~~~~~~~ compilation terminated.

    Which I get past by adding "INC" => "-I../LibYAML/include/", to the Makefile.PL. The tests then fail with things like:

    # Failed test 'require YAML::XS;Can't load '/home/marto/code/yaml-li +byaml-pm/YAML-LibYAML-0.77/blib/arch/auto/YAML/XS/LibYAML/LibYAML.so' + for module YAML::XS::LibYAML: /home/marto/code/yaml-libyaml-pm/YAML- +LibYAML-0.77/blib/arch/auto/YAML/XS/LibYAML/LibYAML.so: undefined sym +bol: yaml_sequence_start_event_initialize at /usr/lib/i386-linux-gnu/ +perl/5.26/DynaLoader.pm line 187

    I'll do some more digging in the morning.

      Oh right, I think I don't get the first error because I have the libyaml package installed, so it's finding the yaml.h from that one instead.

      Tux is actually also working on this...
Re: Separating source files in YAML::XS
by tinita (Parson) on Apr 28, 2019 at 10:09 UTC
    I updated the node. Tux found a way to do it, there's just a weird behavior when doing make test