Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
brodafly opened this issue Sep 29, 2020 · 2 comments

Comments

@brodafly
Copy link

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:

  • Capture-Tiny
  • ExtUtils-CBuilder
  • ExtUtils-ParseXS
  • FFI-CheckLib
  • JSON-PP
  • Module-Load
  • Test-Simple
  • Text-ParseWords
  • Path-Tiny
  • File-Which
  • File-chdir
  • Mojo-DOM58
  • Sort-Versions
  • Alien-Build
  • Alien-Libxml2

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

Best regards,
Stoyan

@shlomif
Copy link
Owner

shlomif commented Oct 29, 2020

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
Copy link

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)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants