配置脚本在 mac 上找不到 libxml2

configure script cannot find libxml2 on mac

当我执行

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

我用 brew 安装了 libxml2 并检查了很多文章,但到目前为止没有任何帮助。


更新

./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

homebrew 安装 libxml2 作为 "keg only" 这意味着它没有符号链接到正常的 /usr/local/include/usr/local/lib 目录...这意味着没有帮助就找不到它。您可以通过 运行ning:

获取以上所有信息
brew info libxml2

如果你运行:

brew ls libxml2

它会告诉您该包中所有文件的完整路径。

如果你也运行:

./configure --help

它应该告诉您需要设置哪些环境变量才能找到 libxml2 因此,有了最后两条信息,您应该能够弄清楚需要设置什么以及如何设置.


我注意到 homebrewlibxml2 列出了一个 pkg-config 文件:

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

也可以通过非特定版本的符号链接获得,如:

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

所以,如果你用 homebrew 安装了 pkg-config,像这样:

brew install pkg-config

解决方案可能只是将路径添加到您的 PKG_CONFIG_PATH 中:

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

然后重新运行你的configure脚本。


注意:只有安装pkg-config(通过brew)后,homebrew才会显示pkg-config 与许多受影响的软件包相关 "caveats",例如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"

不幸的是,出于某种原因,libxml2 似乎并非如此。 (相关 homebrew 问题:“libxml2 install path”。)