You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS7容器配置APR时出现‘未找到XML解析器’错误求助

CentOS7容器编译APR时XML解析器找不到的问题排查与解决

操作过程回顾

  1. 克隆APR源码
git clone https://github.com/apache/apr.git 
  1. 执行./configure触发错误
checking for libxml/parser.h... no
checking Expat 1.95.x... no
checking old Debian-packaged expat... no
checking old FreeBSD-packaged expat... no
checking Expat 1.0/1.1... no
  setting LDFLAGS to "-L/usr/local/lib"
  setting INCLUDES to "-I/usr/local/include"
checking Expat 1.95.x in /usr/local... no
  setting APRUTIL_EXPORT_LIBS to ""
  setting APRUTIL_LIBS to ""
configure: error: No XML parser found!  Please specify --with-expat or --with-libxml2
  1. 尝试安装libxml2
yum install -y libxml2

此时系统中的libxml2库文件:

sh-4.2# ls /usr/lib64/ | grep libxml
libxml2.so.2
libxml2.so.2.9.1

执行./configure --with-libxml2=/usr/lib64/仍报错。

  1. 安装libxml2-devel开发包
yum install libxml2-devel

此时系统中出现动态库链接文件libxml2.so,头文件路径/usr/include/libxml2/libxml/包含完整的XML解析头文件,但执行./configure --prefix=/usr/local/apr --with-libxml2=/usr/lib64/依旧报错。

  1. 尝试添加CFLAGS参数及修改configure文件
CFLAGS="-I/usr/include/libxml2/libxml/"  ./configure 

手动修改configure文件添加头文件路径,问题仍未解决。

  1. 尝试不同的--with-libxml2路径参数
  • ./configure --with-libxml2=/usr/lib64/include/libxml2
  • ./configure --with-libxml2=/usr/include/libxml2
    均触发相同的错误提示。

正确解决方法

步骤1:安装完整的依赖包

除libxml2-devel外,额外安装expat-devel避免后续依赖问题:

yum install -y libxml2-devel expat-devel

步骤2:正确执行configure命令

由于yum安装的库和头文件在系统默认搜索路径中,无需指定复杂路径,直接执行:

./configure --prefix=/usr/local/apr --with-libxml2

若系统无法自动识别路径,可手动指定根目录并补充编译参数:

CFLAGS="-I/usr/include/libxml2" LDFLAGS="-L/usr/lib64" ./configure --prefix=/usr/local/apr --with-libxml2

说明:代码中头文件引用方式为#include <libxml/parser.h>,只需将/usr/include/libxml2加入头文件搜索路径即可,无需指定到libxml子目录。

内容的提问来源于stack exchange,提问作者qg_java_17137

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 08:15:52