PerlAlien / Alien-Libxml2

Install the C libxml2 library on your system
4 stars 3 forks source link

faulty lib / cflags retrieval while building XML::LibXML on Android #10

Closed stuart-little closed 5 years ago

stuart-little commented 5 years ago

In initially posted this on the XML::LibXML issue page to document the problem and was directed here. I figured it might be good to mention, in case anyone else encounters the issue.


I was trying to build XML::LibXML on Android 9 (aarch64) with the termux terminal emulator and perl v5.28.2. The problem was twofold:

(1) the line

CCFLAGS => Alien::Libxml2->cflags . " $Config{ccflags}",

in the XML::LibXML Makefile.PL only provides the include directory

-I/data/data/com.termux/files/usr/include

and not the one-level deeper directory

/data/data/com.termux/files/usr/include/libxml2

where the desired header file libxml/xmlmemory.h is located. This seems to be due to the fact that the Alien::Libxml2->cflags portion of that line is actually empty.

(2) the line

LIBS => [ Alien::Libxml2->libs ],

in the same Makefile.PL fails to pass -lxml2 to the Makefile, which then ends up having no EXTRALIBS.


To address both issues I modified the XML::LibXML Makefile.PL as follows

$ diff <old Makefile.PL file> <new Makefile.PL file>
76,77c76,77
<   CCFLAGS => Alien::Libxml2->cflags . " $Config{ccflags}",
<   LIBS    => [ Alien::Libxml2->libs ],
---
>   CCFLAGS => Alien::Libxml2->cflags . " $Config{ccflags}"  . " -I/data/data/com.termux/files/usr/include/libxml2",
>   LIBS    => Alien::Libxml2->libs .  " -lxml2",

This all works fine now, with everything building and running as expected after implementing said modification, but it might be of use to record the problem here.

plicease commented 5 years ago

Can you provide the full install log of Alien::Libxml2, also the output of these commands, if available would be useful in debugging:

pkg-config --libs libxml-2.0
pkg-config --cflags libxml-2.0
xml2-config --cflags
xml2-config --libs
plicease commented 5 years ago

Also curious if you ran the tests for Alien::Libxml2 if there was a probe error that should have caught it.

stuart-little commented 5 years ago

The requested info follows


$ pkg-config --libs libxml-2.0
-L/data/data/com.termux/files/usr/lib -lxml2
$ pkg-config --cflags libxml-2.0
-I/data/data/com.termux/files/usr/include/libxml2
$ xml2-config --cflags
-I/data/data/com.termux/files/usr/include/libxml2

There's no xml2-libs command. Did you by any chance mean xml2-config --libs? If so:

$ xml2-config --libs
-L/data/data/com.termux/files/usr/lib -lxml2 -L/data/data/com.termux/files/usr/lib -lz -L/data/data/com.termux/files/usr/lib -llzma -liconv -lm

About the Alien::Libxml2 installation: it was through CPAN, and initially I did not install it directly. It must have been pulled when I tried to install XML::LibXML with notest. So no, initially I did not run the tests.

What I see now, after uninstalling it with cpanm and trying again: with notest it installs fine. Without it, i.e. when I do run the tests, the installation fails. You can see output from both commands:

$ cpan Alien::Libxml2

here

$ cpan -Ti Alien::Libxml2

here

plicease commented 5 years ago

Yes I typo'd the command should have been:

xml2-config --libs

This output doesn't explain what you reported earlier. The diagnostic shows the correct include directory for ->cflags and -lxml2 for ->libs.

As for the test failure, it seems as though the configuration provided by libxml2 is wrong. Neither pkg-config nor xml2-config are providing the appropriate -I flags to find inconv.h, and the pkg-config probably isn't providing the correct -L flag for libiconv (although it doesn't get to the link step thanks to the compile error, so depending on the library search order that may be fine). These problems should be reported to the vendor.

stuart-little commented 5 years ago

As for the test failure, it seems as though the configuration provided by libxml2 is wrong. Neither pkg-config nor xml2-config are providing the appropriate -I flags to find inconv.h, and the pkg-config probably isn't providing the correct -L flag for libiconv (although it doesn't get to the link step thanks to the compile error, so depending on the library search order that may be fine). These problems should be reported to the vendor.

I suppose the vendors in question would be the folks over at termux. Let me try to understand what the problem to report is:

First off, I when I made the previous post I did not have the libiconv-dev package installed and there was no iconv.h file anywhere on the system to begin with. There is now, but which pkg-config command should I run to test whether pkg-config sees iconv properly?

I have checked that there are no *iconv* files in $PREFIX/lib/pkgconfig. Is that the issue I should be reporting?

stuart-little commented 5 years ago

Ah, you know what? After installing libiconv-dev the Alien::Libxml2 install went through fine with tests: the new output of

$ cpan Alien::Libxml2

is here.

plicease commented 5 years ago

iconv may not provide a .pc file (many packages do not), but if libxml2 uses it then it is its responsibility that it pass on the appropriate flags for its use via its .pc file. Since you only needed to install libiconv-dev that tells me that the iconv.h and libiconv are already in the appropriate system level paths. libiconv-dev probably should be a dependency of (I'm guessing the package name) libxml2-dev, though I am not familiar with the package system used by termux. Curious if XML::LibXML2 installs cleanly now?

stuart-little commented 5 years ago

iconv may not provide a .pc file (many packages do not), but if libxml2 uses it then it is its responsibility that it pass on the appropriate flags for its use via its .pc file. Since you only needed to install libiconv-dev that tells me that the iconv.h and libiconv are already in the appropriate system level paths. libiconv-dev probably should be a dependency of (I'm guessing the package name) libxml2-dev, though I am not familiar with the package system used by termux.

I see; thank you for clarifying. Yes, that package is indeed libxml2-dev.

Curious if XML::LibXML2 installs cleanly now?

It did! I uninstalled it with cpanm and then issued

cpan XML::LibXML

It went through fine, tests and all. I think I'll report this back in the original XML::LibXML thread too.

Thank you for all the help.

plicease commented 5 years ago

Great thanks for reporting this, I think there is probably a useful FAQ for this, although I haven't formulated it quite yet.