Search code examples
macoshomebrewlibxml2configure

configure script cannot find libxml2 on mac


when I execute

./configure
...
checking for libxml-2.0... no
configure: error: Library libxml2 not found, install library or build without (using --disable-xml).

I installed libxml2 with brew and checked a lot of articles, but nothing helped so far.


UPDATE

./configure --help
Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor
  PKG_CONFIG  path to pkg-config utility
  PKG_CONFIG_PATH
              directories to add to pkg-config's search path
  PKG_CONFIG_LIBDIR
              path overriding pkg-config's built-in search path
  libxml2_CFLAGS
              C compiler flags for libxml2, overriding pkg-config
  libxml2_LIBS
              linker flags for libxml2, overriding pkg-config

Solution

  • homebrew installs libxml2 as "keg only" which means it is not symlinked to the normal /usr/local/include and /usr/local/lib directories... which means nothing can find it without help. You can get all the above info by running:

    brew info libxml2
    

    If you run:

    brew ls libxml2
    

    it will tell you the full paths to all the files in that package.

    If you also run:

    ./configure --help
    

    it should tell you what environment variables you need to set in order to find libxml2 So, armed with these last two pieces of info, you should be able to work out what you need to set and how.


    I note there is a pkg-config file listed for libxml2 by homebrew at:

    /usr/local/Cellar/libxml2/2.9.10/lib/pkgconfig/libxml-2.0.pc
    

    which is also available via a non-version-specific symlink as:

    /usr/local/opt/libxml2/lib/pkgconfig/libxml-2.0.pc
    

    so, if you have installed pkg-config with homebrew, like this:

    brew install pkg-config
    

    the solution may be just to add the path for that to your PKG_CONFIG_PATH with:

    export PKG_CONFIG_PATH=/usr/local/opt/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH
    

    and then to rerun your configure script.


    Note: It is only after installing pkg-config (via brew) that homebrew will display pkg-config related "caveats" for many affected packages e.g. libffi:

    ==> Caveats
    libffi is keg-only, which means it was not symlinked into /usr/local,
    because some formulae require a newer version of libffi.
    
    For compilers to find libffi you may need to set:
      export LDFLAGS="-L/usr/local/opt/libffi/lib"
    
    For pkg-config to find libffi you may need to set:
      export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
    

    Unfortunately, however, this appears not to be the case for libxml2 for some reason. (Related homebrew issue: "libxml2 install path".)