5

I'm trying to fix a bug in libxml2. I cannot get it to compile with --with-icu when using --prefix=/Server/software. I have submitted a bug report here, but I need to get it to compile for resolving a conflict when compiling PHP with intl support. I suspect it's a problem with the Makefile. My experience with Makefile's is limited. The desired result is coming up with a patch that can be submitted to the linked bug report.

The --with-icu flag causes LIBXML_ICU_ENABLED to be defined. The included code is supposed to resolve a conflict when including headers from both icu and libxml2 (specifically, both use UChar). The PHP plugin intl, activated with --enable-intl, requires icu. libxml2 is needed by PHP for DOM/XML functions.

There are two problems.

First, this config:

./configure --prefix=/Server/software --enable-shared --enable-static --with-icu

Results in:

configure: error: libicu config program icu-config not found

This happens because of this code in configure.in:

WITH_ICU=0
if test "$with_icu" != "yes" ; then
    echo Disabling ICU support
else
    ICU_CONFIG=icu-config
    if ${ICU_CONFIG} --cflags >/dev/null 2>&1
    then
        ICU_LIBS=`icu-config --ldflags`
        LDFLAGS="$LDFLAGS $ICU_LIBS"
        WITH_ICU=1
        echo Enabling ICU support
    else
        AC_MSG_ERROR([libicu config program icu-config not found])
    fi
fi

Specifically ICUCONFIG=icu-config isn't respecting --prefix=/Server/software. I can work around this by doing export PATH=/Server/software/bin:$PATH.

This "fixes" the ./configure problem.

Second, when I run make I get errors, the most relavent being:

./include/libxml/encoding.h:31:26: error: unicode/ucnv.h: No such file or directory

The unicode/uncv.h file is in /Server/software/include/unicode/uncv.h. I suspect the compiler is looking for this file in the local directory and in my /usr directory.

This is what the error is referring to:

#ifdef LIBXML_ICU_ENABLED
#include <unicode/ucnv.h>
#endif

Clearly this is a path issue when using --with-icu and --prefix=/Server/software. Without --with-icu it compiles fine, but this is needed to resolve a define UChar conflict when compiling PHP with both icu and libxml2.

The result of icu-config --cflags is:

-O2 -Wall -ansi -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -Wno-long-long

This is being piped into /dev/null.

The result of icu-config --ldflags is:

-lpthread -lm -L/Server/software/lib -licui18n -licuuc -licudata -lpthread -lm

What needs to be changed to resolve these issues?

Luke
  • 13,678
  • 7
  • 45
  • 79

1 Answers1

2

So, take a look at where it's using icu-config. It should be doing something like icu-config --cppflags which should set -I/Server/Software/include or similar. You could work around it by setting CPPFLAGS to include such a parameter yourself.

Can you include the actual compile command line immediately before the error?

Sounds like a bug in libxml - it ought to search ${PREFIX}/bin for icu-config.

Also, ICU now exports pkg-config files, which are more of a standard way to find such items.


Try this before WITH_ICU :

    ICU_CPPFLAGS=`icu-config --cppflags`
    CPPFLAGS="$CPPFLAGS $ICU_CPPFLAGS"

update I'm going to quote Luke's last response. Glad it's working.

I solved the linker problems, so now it all works. For this question using libxml 2.7.7 was the solution. It seems OX X 10.6 ships with 2.7.8. So for it to work you have to compile libxml2 yourself with 2.7.7. The linker problems are solved by adding LIBS="-lresolv -lstdc++" just before PHP's ./configure. If installing to a non-standard location you also need to compile ICU with --enable-rpath. I've accepted your answer. Feel free to update it with this information :). – Luke 17 hours ago

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
Steven R. Loomis
  • 4,228
  • 28
  • 39
  • I updated the question to include the more relavent parts of configure.in and the output of icu-config when used in `configure.in`. It appears `icu-config --ldflags` is supposed to pass `/Server/software` to make the include work in `encoding.h`, but it's not getting through. Trying to find other packages that may do something similar. – Luke Nov 02 '11 at 22:27
  • Well that seems to have fixed the problem with building libxml2. But now my PHP's config fails with `checking whether libxml build works... no`. The relavant bit in config.log being `configure:21707: gcc -o conftest -fvisibility=hidden -no-cpp-precomp -Wl,-rpath,/Server/software/lib -L/Server/software/lib conftest.c`. Without compiling libxml2 with `--with-icu` PHP is fine (if I don't include `--enable-intl`, which I need). – Luke Nov 03 '11 at 18:20
  • @Luke what does config.log in php say? Intl uses ICU as I assume you are aware. intl is using the same ICU you are using for libxml2, right? – Steven R. Loomis Nov 03 '11 at 19:21
  • Yes, same ICU. Here is config.log http://pastebin.com/qKezu2Z3 and here are the commands i'm using http://pastebin.com/dYQwUCm0 along with the patch file http://pastebin.com/ss0L6ZLw . Make sure the patch file and script are both in /Server if you run it. – Luke Nov 03 '11 at 22:02
  • @Luke line 092. and following look OK- the blank line is a bit strange - but it doesn't show the actual error. If you run 'gcc -o conftest .. ' yourself with the specified contents of conftest.c does it work? Need to find the actual error here. – Steven R. Loomis Nov 03 '11 at 23:34
  • conftest.c doesn't exist. There is a conftest.cpp though. Not sure why PHP is deciding to use "conftest.c" verses "conftest.cpp", but I think it has something to do with the "configure" file. For some reason libxml2 with icu seems to make it use the .c version, which doesn't exist. – Luke Nov 04 '11 at 16:18
  • @Luke configure creates conftest.c with: " char xmlInitParser(); int main() { xmlInitParser(); return 0; }" and compiles it with: gcc -o conftest -g -O2 -fvisibility=hidden -no-cpp-precomp -Wl,-rpath,/Server/software/lib -L/Server/software/lib conftest.c -lm -lxml2 -lz -liconv -lm can you try creating that file (without the quotes) and compiling/runnning it yourself and see what happens? – Steven R. Loomis Nov 04 '11 at 18:42
  • That works fine. No output. "conftest" binary is created. Something about adding icu support to libxml2 really throws PHP's build out of whack. – Luke Nov 04 '11 at 20:17
  • @Luke can you execute the conftest binary? Sounds like there's some problem with the autoconf not reporting back the actual issue. EDIT: I assumed that 'no output' meant the compiler, not the conftest binary. The only other thing I thought of is that perhaps it is an older ICU version which outputs newlines in the icu-config output, since your config.log shows newlines in the compiler output. Which ICU are you using? (4.8.1.1 recommended) – Steven R. Loomis Nov 07 '11 at 19:36
  • I'm using 4.8.1.1. I discovered there is a problem with the most recent version of libxml2, 2.7.8. The --with-icu flag was introduced in 2.7.8. Stepping abck to 2.7.7 resolves all the issues I had before (including UChar). Now I'm having symbol issues with the PHP compiler. The intl extension appears to be the only C++ extension. – Luke Nov 07 '11 at 19:57
  • @Luke sounds like in the best case there's already a bug with libxml2's detection of ICU. Sorry, not sure what else to suggest here. – Steven R. Loomis Nov 07 '11 at 21:53
  • I solved the linker problems, so now it all works. For this question using libxml 2.7.7 was the solution. It seems OX X 10.6 ships with 2.7.8. So for it to work you have to compile libxml2 yourself with 2.7.7. The linker problems are solved by adding LIBS="-lresolv -lstdc++" just before PHP's ./configure. If installing to a non-standard location you also need to compile ICU with --enable-rpath. I've accepted your answer. Feel free to update it with this information :). – Luke Nov 07 '11 at 22:20
  • @Luke ICU bug: http://bugs.icu-project.org/trac/ticket/10465 with work in progress code linked to the bugzilla bug 663214 above. – Steven R. Loomis Jan 31 '14 at 00:37
  • `./configure --prefix=/path/libxml2 CPPFLAGS=-I/path/icu/include --with-icu` The complete configure command should be like this. – Lan Nguyen Jul 28 '16 at 18:34