shlomif / perl-XML-LibXML

The XML-LibXML CPAN Distribution for Processing XML using the libxml2 library
https://metacpan.org/release/XML-LibXML
Other
17 stars 35 forks source link

Can't link zlib and libxml2 statically during build time with the newer versions #53

Open brodafly opened 3 years ago

brodafly commented 3 years ago

Hello!

I see there has been major updates in the build process of XML::LibXML since version 2.0200 and the introduced dependency to Alien::Libxml2. The project I'm trying to build (a self contained perl + several CPAN modules) was using version 2.0132 and was statically linking zlib and libxml2 at build time by providing the INC and LIBS args to Makefile.PL. How would one go about doing that now that Alien::Libxml2 is used? I couldn't find any any information and my own attempts turned out futile.

Previously with 2.01* versions the Makefile.PL was invoked like so:

---------- Purpose: building module XML-LibXML-2.0132
--- Running: /git/perl/gen/out/perl-5.30.3/bin/perl Makefile.PL PERL=/git/perl/gen/out/perl-5.30.3/bin/perl INC=-I/git/perl/gen/out/build-perl/libxml_helpdir/include LIBS=-L/git/perl/gen/out/build-perl/libxml_helpdir/lib

... and this resulted in the following call during the make phase to produce the LibXML.so:

cc  -shared -O2 -fstack-protector --param=ssp-buffer-size=8 -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -L/usr/local/lib  Av_CharPtrPtr.o Devel.o LibXML.o dom.o perl-libxml-mm.o perl-libxml-sax.o xpath.o  -o blib/arch/auto/XML/LibXML/LibXML.so  \
   -L/git/perl/gen/out/build-perl/libxml_helpdir/lib -lxml2 -lz -lm   \

Now with version 2.0206 the provided INC and LIBS arguments are ignored, and LibXML.so is produced like so:

cc  -shared -O2 -fstack-protector --param=ssp-buffer-size=8 -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -L/usr/local/lib  Av_CharPtrPtr.o Devel.o LibXML.o dom.o perl-libxml-mm.o perl-libxml-sax.o xpath.o  -o blib/arch/auto/XML/LibXML/LibXML.so  \
      \

This results in an undefined symbol error when I try to use XML::LibXML:

/git/perl/gen/out/perl-5.30.3/bin # ./perl ~/temp/xml.pl
Can't load '/git/perl/gen/out/perl-5.30.3/lib/auto/XML/LibXML/LibXML.so' for module XML::LibXML: /git/perl/gen/out/perl-5.30.3/lib/auto/XML/LibXML/LibXML.so: undefined symbol: xmlTextReaderStandalone at /git/perl/gen/out/perl-5.30.3/lib/DynaLoader.pm line 193.
 at /git/perl/gen/out/perl-5.30.3/lib/XML/LibXML.pm line 156.
BEGIN failed--compilation aborted at /git/perl/gen/out/perl-5.30.3/lib/XML/LibXML.pm line 156.
Compilation failed in require at /root/temp/xml.pl line 2.
BEGIN failed--compilation aborted at /root/temp/xml.pl line 2.

Alien::Libxml2 did its job of providing a libxml2 library from xmlsoft.org, but that's of no use to me since I want to use my own. Not to mention that my build infrastructure prohibits outbound connectivity and that causes the Alien::Libxml2 build itself to fail. The output above is from another machine that does not have such a constraint.

TL;DR Can you suggest a way to statically link zlib and libxml2 during XML::LibXML's build time, preferably circumventing the need to use Alien::Libxml2 or at least stopping it from doing outbound connections to satisfy the "missing" dependency. Are there plans to remove the Alien::Libxml2 dependency for such use cases? I ended up needing to add the following CPAN modules to the project just to upgrade to the newest version of XML::LibXML:

Enough babbling on my side... Hopefully I managed to explain my issue 😃

Best regards, Stoyan

shlomif commented 3 years ago

Hi @brodafly ! Sorry for the late reply. First of all, did you manage on your own eventually? Otherwise, there are https://metacpan.org/pod/CPAN::Mini::Inject and similar solutions for non-networked cpan access. I am not an Alien::* expert, just accepted some PRs to replace some complex EU::MM code with them. I can try to answer your question about static linking by studying the docs or the source; you may also be able to do so.

mtsanovv commented 5 months ago

Hi @shlomif, I stumbled upon the same issue more than 3 years later. I tried studying the Makefile.PL of XML::LibXML and Alien::Libxml2's alienfile but I got nowhere. In my case, I need to make XML::LibXML to link statically against zlib, liblzma and libxml2. Previously, I was modifying Makefile.PL manually before building XML::LibXML. There, I changed the $Config LIBS, INC and LDFLAGS properties in the try_libconfig method that's now gone: https://github.com/shlomif/perl-XML-LibXML/blob/2cf922a3d1417336b5591c437b2d257f9b39435a/Makefile.PL.

I'm wondering - should I try adding those flags now to the $Config of XML::LibXML's Makefile.PL or to Alien::Libxml2's alienfile (somehow)?