Opened 6 years ago

Last modified 5 years ago

#57990 reopened defect

libxml2 @2.9.7_2: ICU include directory not in pkg-config output

Reported by: dsedivec Owned by: ryandesign (Ryan Carsten Schmidt)
Priority: Normal Milestone:
Component: ports Version: 2.5.4
Keywords: Cc: raimue (Rainer Müller), MarcusCalhoun-Lopez (Marcus Calhoun-Lopez), ryandesign (Ryan Carsten Schmidt), elfprince13 (Thomas Dickerson)
Port: libxml2

Description (last modified by ryandesign (Ryan Carsten Schmidt))

Since libxml2 now builds against ICU, I cannot build software against MacPorts libxml2 without manually including -I$prefix/include when building. Quick example:

$ command -v pkg-config
/opt/local/bin/pkg-config

$ cat repro.c
/* Include inspired by PostGIS's configure script: */
#include <libxml/tree.h>

int main() { return 0; }

$ clang $(pkg-config --cflags libxml-2.0) repro.c $(pkg-config --libs libxml-2.0)
In file included from repro.c:2:
In file included from /opt/local/include/libxml2/libxml/tree.h:1307:
In file included from /opt/local/include/libxml2/libxml/xmlmemory.h:218:
In file included from /opt/local/include/libxml2/libxml/threads.h:35:
In file included from /opt/local/include/libxml2/libxml/globals.h:18:
In file included from /opt/local/include/libxml2/libxml/parser.h:810:
/opt/local/include/libxml2/libxml/encoding.h:31:10: fatal error: 'unicode/ucnv.h' file not found
#include <unicode/ucnv.h>
         ^~~~~~~~~~~~~~~~
1 error generated.

$ clang -I/opt/local/include $(pkg-config --cflags libxml-2.0) repro.c $(pkg-config --libs libxml-2.0)

$ ls a.out
a.out*

After a brief conversation on IRC it was requested that I open a ticket for this, since the ICU cflags/libs flags should probably be included in pkg-config output for libxml-2.0 now. (It was also suggested that maybe this is really an upstream issue, rather than MacPorts.)

Change History (14)

comment:1 Changed 6 years ago by mf2k (Frank Schima)

Cc: MarcusCalhoun-Lopez added

Cc'ing committer of that change for possible comment.

comment:2 Changed 6 years ago by kencu (Ken)

Hi -- it would be most helpful if you could include your main.log and your configure.log files as well (please attach them to this ticket.

I get this:

checking for ICU... yes
Enabled Schemas/Relax-NG support
checking for printf... yes
checking for sprintf... yes

and the port builds right through to the end with icu support enabled.

So it's likely to be something on your system somewhere that is messing you up. The usual culprits are homebrew and anything you have installed in /usr/local.

comment:3 Changed 6 years ago by raimue (Rainer Müller)

This is not about building in MacPorts (therefore no main.log required), because with MacPorts ${prefix}/include would always be in the include path and this bug will not occur. This is about using libxml2 to compile software outside of MacPorts. The CFLAGS provided by pkg-config are insufficient as the libxml/*.h headers will try to include unicode/*.h and therefore the path to these headers also needs to be added to the pkg-config file.

comment:4 Changed 6 years ago by ryandesign (Ryan Carsten Schmidt)

Cc: ryandesign added
Description: modified (diff)

And just blindly adding -I${prefix}/include to libxml2's pkgconfig file can have other consequences. See how I fixed this issue for glib2 by patching glib2's header to #include the absolute path of the non-glib2 header it was requiring. I suggest doing something similar for libxml2: patching encoding.h so that it #includes the absolute path of ucnv.h.

comment:6 in reply to:  3 Changed 6 years ago by kencu (Ken)

Replying to raimue:

This is not about building in MacPorts (therefore no main.log required), because with MacPorts ${prefix}/include would always be in the include path and this bug will not occur. This is about using libxml2 to compile software outside of MacPorts. The CFLAGS provided by pkg-config are insufficient as the libxml/*.h headers will try to include unicode/*.h and therefore the path to these headers also needs to be added to the pkg-config file.

Ah, you're right, I didn't notice that.

Seems this exact same issue could easily afflict dozens or hundreds of MacPorts' ports? Any port that calls another ports' headers would be similarly affected by this.

Is it so rare that one-off fixes are the way to go?

comment:7 Changed 6 years ago by ryandesign (Ryan Carsten Schmidt)

Only ports whose normal include files are not in /opt/local/include.

comment:8 Changed 6 years ago by dsedivec

Sorry to potentially move the goalposts, but I've now noticed a similar problem with libs and thought maybe I should bring it up here:

$ pkg-config --libs libxml-2.0
-L/opt/local/lib -lxml2

$ xml2-config --libs
-L/opt/local/lib -lxml2 -L/opt/local/lib -lz -L/opt/local/lib -llzma -lpthread -liconv -L/opt/local/lib -licui18n -licuuc -licudata -lm

Note that xml2-config knows about the ICU libraries, but pkg-config doesn't. (--cflags is same for both pkg-config and xml2-config.)

This is making me wonder if I'm even supposed to be using pkg-config with libxml2?

comment:9 Changed 6 years ago by raimue (Rainer Müller)

The output of pkg-config is correct. The other libraries are not required for dynamic linking; only direct dependencies have to be given to the linker. If you add the --static flag, you will also see all the other libraries. I would recommend to use pkg-config as the output from xml2-config will lead to so called overlinking.

comment:10 Changed 6 years ago by elfprince13 (Thomas Dickerson)

Cc: elfprince13 added

comment:11 Changed 6 years ago by ryandesign (Ryan Carsten Schmidt)

Owner: set to ryandesign
Resolution: fixed
Status: newclosed

In dcef2c394d854e1cade1dd1a706039dc4929d2c4/macports-ports (master):

libxml2: Include iconv and icu by absolute path

Closes: #57990

comment:12 Changed 5 years ago by raybellis (Ray Bellis)

Resolution: fixed
Status: closedreopened

This fix is insufficient.

unicode/ucnv.h in turn does #include "unicode/uvnc_err.h" and some further includes which then also fail when /opt/local/include is not in the search path.

(found with icu @58.2_2, when trying to build BIND 9 from the ISC sources outside of the MacPorts system but using libraries provided by MacPorts).

comment:13 Changed 5 years ago by elfprince13 (Thomas Dickerson)

Just wanted to bump this and say that the fix actually made things worse in terms of the number of files that have problems.

comment:14 Changed 5 years ago by kiwiroy (Roy Storey)

Please see report at https://github.com/Perl5-Alien/Alien-Libxml2/issues/13

Alien::Libxml2 detects system libxml2 (macports provided here), but the tests fail for the reason Ray mentions.

As a fix locally I’ve modified the last line of libxml-2.0.pc to read.

Cflags: -I${includedir}/libxml2 -I${includedir}

I assume ports that depend port:libxml2 aren’t affected as they have includedir (/opt/local/include) in CFLAGS anyway.

Note: See TracTickets for help on using tickets.