从源代码构建Apache Httpd:致命错误:expat.h文件不存在

21

我正在尝试在RHEL 7.3上构建Apache服务器v2.4.38,并且我正在使用apr 1.6.5,apr-util 1.6.1和pcre 8.42。

我正在运行以下命令:

./configure  --with-included-apr --with-pcre=/data/abc/installed/pcre_installed --prefix=/data/abc/installed/httpd_installed  

make

在运行“make”时,我收到了错误提示。

/bin/sh /data/abc/installed/httpd-2.4.38/srclib/apr/libtool --silent --mode=compile gcc -g -O2 -pthread   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I/data/abc/installed/httpd-2.4.38/srclib/apr-util/include -I/data/abc/installed/httpd-2.4.38/srclib/apr-util/include/private  -I/data/abc/installed/httpd-2.4.38/srclib/apr/include    -o xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
 #include <expat.h>

1
我无法执行“yum install expat-devel”,因为它需要sudo访问权限。 - Amit Dube
如果你没有 root 访问权限,为什么要从源代码构建 Apache?! - cnst
我想在我的机器上启动httpd服务器。是否可以在没有root访问权限的情况下使用rpm软件包安装Apache Httpd? - Amit Dube
除非您拥有 root 访问权限,否则无法使其侦听端口 80,因此,您只能将其工作在像 8080 这样的端口上(通常,低于 1024 的端口是保留的)。 - cnst
4个回答

21

https://libexpat.github.io/下载 expat-2.2.6.tar.bz2。

使用以下命令提取 expat:

tar xvjf expat-2.2.6.tar.bz2 -C /path-to-dir

切换到提取的 expat 目录。

使用以下命令构建 expat:

  1. ./configure --prefix=/path-to-expat-installation-dir

  2. make

  3. make install

在从源代码构建 Apache Httpd 时,指定 --with-expat 参数。

./configure --with-included-apr --prefix=/path-to-apache-installation --with-expat=/path-to-expat-installation-dir


10

对于其他遇到这个问题的人:

OP需要这样做是因为他们没有sudo访问权限。如果你有,通常不需要手动下载expat源码;通过包管理器安装要容易得多。除非你编译的软件需要比你的RPM仓库提供的expat版本更新的版本。

所以,在RHEL系列的操作系统中,你只需执行sudo <dnf|yum> install expat expat-devel,然后继续进行你要编译的操作。


4
针对Debian/Ubuntu系列操作系统:执行apt install libexpat1-dev安装libexpat1开发库。 - Jesferman
在SLES上,这个包的名称是libexpat-devel - 所以我不得不以"sudo zypper install libexpat-devel"的方式进行安装 - 但是那个库似乎会引起问题,就像https://dev59.com/UaHia4cB1Zd3GeqPVpMt中描述的那样。 - Yogesh Devi

2

在Ubuntu中尝试
apt install libexpat1-dev
对于RHEL,我建议使用@cyqsimon的答案


libexpat1-dev修复了我在Debian上的问题。 - kingsjester

2
您是否已安装了expat库?(因为expat.h就是从那里来的。) 如果您无法全局安装到系统中,我相信Apache的`./configure`脚本一定有一个选项来支持自定义库的位置。

在./configure中是否有参数可以指定exapt库的路径? - Amit Dube
1
尝试运行 ./configure --help | fgrep expat ?! - cnst

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接