PerlAlien / Alien-Libxml2

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

Cannot build Alien-Libxml2 on OS X #11

Closed PhilipSharman closed 5 years ago

PhilipSharman commented 5 years ago

Hello, I'm having problems installing Alien::Libxml2 on OS X.

  1. I tried to use cpan to install Alien::Libxml2, but it failed with this message:

    The installed system version of libxml2 2.9.4 is not compatible with 
    +XML::LibXML (and probably buggy)!"
    ...
    # Failed test 'xs'
    # at t/alien_libxml2.t line 10.
    #   ExtUtils::CBuilder->compile failed
    #     error building testalienjPkRO/test.o from 'testalienjPkRO/test.c
    +' at /Users/psharman/perl5/perlbrew/perls/perl-5.30.0/lib/5.30.0/ExtU
    +tils/CBuilder/Base.pm line 185.
    #     cc -I/Users/psharman/perl5/perlbrew/perls/perl-5.30.0/lib/5.30.0
    +/darwin-2level/CORE -I/usr/include/libxml2 -c -fno-common -DPERL_DARW
    +IN -mmacosx-version-min=10.14 -fno-strict-aliasing -pipe -fstack-prot
    +ector-strong -I/usr/local/include -DPERL_USE_SAFE_PUTENV -O3 -o testa
    +lienjPkRO/test.o testalienjPkRO/test.c
    #     testalienjPkRO/test.xs:5:10: fatal error: 'libxml/parser.h' file
    + not found
    #     #include <libxml/parser.h>
    #              ^~~~~~~~~~~~~~~~~>
  2. So I used Homebrew to install a more up to date copy of libxml2 and I've put that copy early in the path. Now if I do xml2-config --version I get the new version 2.9.9.

  3. But when I try again to install Alien::Libxml2 via cpan, I get the same error message. It still finds the old 2.9.4 version.

  4. I then tried to install Alien::Libxml2 manually and specify some paths to the makefile. EG:

    perl Makefile.PL LIBS="-LC:/usr/local/Cellar/libxml2/2.9.9_2/lib -llibxml2" INC="-IC:/usr/local/Cellar/libxml2/2.9.9_2/include"

    But that didn't work either. I still get the fatal error: 'libxml/parser.h' file not found error.

  5. I've asked on Perl Monks, but haven't found an answer that works for me.

This is using OS X 10.14.5 (Mojave) . I've tried with both Perl 5.28.2 and 5.30.0.

Thanks for any assistance you can give. I'm probably missing something obvious.

Regards, Philip.

plicease commented 5 years ago

Can you provide the output of:

pkg-config libxml-2.0 --libs
pkg-config libxml-2.0 --cflags

thanks.

PhilipSharman commented 5 years ago
pkg-config libxml-2.0 --libs
-lxml2

 pkg-config libxml-2.0 --cflags
-I/usr/include/libxml2

Thanks.

plicease commented 5 years ago

So it looks like Apple ships a broken version of libxml2 cool. I'll rework the alienfile to prefer xml2-config over pkg-config. That seems to make more sense anyhow.

plicease commented 5 years ago

@PhilipSharman can you try https://cpan.metacpan.org/authors/id/P/PL/PLICEASE/Alien-Libxml2-0.10_01.tar.gz

PhilipSharman commented 5 years ago

Thanks, that seems to work!

PhilipSharman commented 5 years ago

P.S. Just to clarify what I have on my machine ...


1) What is installed by default on OS X:

- Using this location for `xml-2config`: \
  `/usr/bin/xml2-config`

    `xml2 config -version` reports:\
    `2.9.4`

    `xml2 config -libs`  reports:\
    `-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib -lxml2 -lz -lpthread -licucore -lm`

    `xml2 config -cflags`  reports:\
    `-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/libxml2`

- (There doesn't seem to be a `pkg-config` installed by default.)

2) What is installed by Homebrew:

- Using this location for `xml-2config`: \
`/usr/local/Cellar/libxml2/2.9.9_2/bin/xml2-config`

    `xml2 config -version`  reports:\
    `2.9.9`

    `xml2 config -libs`  reports:\
    `-L/usr/local/Cellar/libxml2/2.9.9_2/lib -lxml2 -lz -lpthread -liconv -lm`

    `xml2 config -cflags`  reports:\
    `-I/usr/local/Cellar/libxml2/2.9.9_2/include/libxml2`

- Using this location for `pkg-config`: \
`/usr/local/bin/pkg-config` \
 ... which is a symbolic link to ... \
`../Cellar/pkg-config/0.29.2/bin/pkg-config`

    `pkg-config libxml-2.0 --libs` reports: \
    `-lxml2`

    `pkg-config libxml-2.0 --cflags` reports: \
    `-I/usr/include/libxml2`

    But there is no `/usr/include` directory.

     P.S.
plicease commented 5 years ago

Yeah apple doesn't provide pkg-config or /usr/include in recent versions of their OS (not sure if they ever provided pkg-config). They do provide the .dylib files for run-time compatibility of existing software, but they also apparently provide the .pc files that no longer work without the headers in /usr/include, which are picked up by pkg-config homebrew. IMO apple should not ship the broken .pc files that would pretty much fix everything. There are probably workarounds that homebrew could make (since it is providing its own pkg-config), like not using the broken .pc files or putting its .pc file for libxml2 et. al before the broken system .pc files.

plicease commented 5 years ago

Released the fix as 0.11. Sorry for the long delay on making a production release, I lost track of things.

MichaelGrundie commented 4 years ago

Any advice on how I can get this working on MacOS Catalina v10.15.7

I have tried the steps detailed by Philip but still hit the same issue:

#     #include <libxml/parser.h>
#              ^~~~~~~~~~~~~~~~~
#     1 error generated.\`
▶ which xml2-config
/usr/local/opt/libxml2/bin/xml2-config

▶ xml2-config --version
2.9.10

▶ xml2-config --libs
-L/usr/local/Cellar/libxml2/2.9.10_1/lib -lxml2 -lz -lpthread -liconv -lm

▶ xml2-config --cflags
-I/usr/local/Cellar/libxml2/2.9.10_1/include/libxml2

▶ pkg-config libxml-2.0 --libs
-lxml2

▶ pkg-config libxml-2.0 --cflags
<No Output>

▶ xml2-config --libs
-L/usr/local/Cellar/libxml2/2.9.10_1/lib -lxml2 -lz -lpthread -liconv -lm

▶ xml2-config --cflags
-I/usr/local/Cellar/libxml2/2.9.10_1/include/libxml2

▶ which pkg-config
/usr/local/bin/pkg-config

▶ ls -l /usr/local/bin/pkg-config
lrwxr-xr-x  1 mg  admin  44 29 Jun 13:24 /usr/local/bin/pkg-config -> ../Cellar/pkg-config/0.29.2_3/bin/pkg-config
plicease commented 4 years ago

@MichaelGrundie please provide the full output of the test fail on this issue: https://github.com/PerlAlien/Alien-Libxml2/issues/23