Apache 2 交叉编译,apr-1.7.0、apr-util-1.6.1
Apache 2 交叉编译,apr-1.7.0、apr-util-1.6.1
关于交叉编译 Apache 的文章很多,但其中 apr、apr-util 版本较低,本文假设你已针对低版本编译成功,仅记录在编译新版本时遇到的2个新问题及解决方法。
注意:
- 如果选择 apr-1.4.5 、apr-util-1.3.12,则不会遇到下述问题,奈何本人有更新强迫症。
- 请根据实际情况修改路径、工具链。
环境
截至 2021-05-23,httpd、pcre、apr、apr-util、expat 均是最新版本。
- Ubuntu 18.04.1
- 交叉编译工具链:gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf
- httpd-2.4.46
- pcre-8.44
- apr-1.7.0,解压后复制到 httpd-2.4.46/srclib 中
- apr-util-1.6.1,解压后复制到 httpd-2.4.46/srclib 中
- expat-2.3.0
交叉编译结果
apr 版本 | 时间 | apt-util 版本 | 时间 | 编译结果 |
---|---|---|---|---|
apr-1.4.5 | 2012-02-14 | apr-util-1.3.12 | 2011-05-20 | 通过 |
apr-1.7.0 | 2020-07-06 | apr-util-1.3.12 | 2011-05-20 | 通过,apr_lock_method=USE_SYSVSEM_SERIALIZE |
apr-1.7.0 | 2020-07-06 | apr-util-1.4.1 | 2011-12-13 | 通过,apr_lock_method=USE_SYSVSEM_SERIALIZE |
apr-1.7.0 | 2020-07-06 | apr-util-1.5.4 | 2014-09-20 | 通过,apr_lock_method=USE_SYSVSEM_SERIALIZE |
apr-1.7.0 | 2020-07-06 | apr-util-1.6.0 | 2017-06-12 | 通过,expat.h,XML_xxx,–with-expat |
apr-1.7.0 | 2020-07-06 | apr-util-1.6.1 | 2020-07-06 | 通过,expat.h,XML_xxx,–with-expat |
问题
问题1:error: ‘mutex_proc_pthread_methods’ undeclared
locks/unix/proc_mutex.c: In function ‘proc_mutex_choose_method’:
locks/unix/proc_mutex.c:1494:28: error: ‘mutex_proc_pthread_methods’ undeclared (first use in this function); did you mean ‘mutex_flock_methods’?
new_mutex->meth = &mutex_proc_pthread_methods;
^~~~~~~~~~~~~~~~~~~~~~~~~~
mutex_flock_methods
locks/unix/proc_mutex.c:1494:28: note: each undeclared identifier is reported only once for each function it appears in
该问题由 apr 导致,分析 proc_mutex.c
文件,程序执行到 #elif APR_USE_PROC_PTHREAD_SERIALIZE
分支报错,进一步跟踪到 APR_USE_PROC_PTHREAD_SERIALIZE
是在 apr/include/apr.h
中定义,对比 apr-1.4.5 和 apr-1.7.0 的相关位置。
// apr-1.4.5
#define APR_USE_FLOCK_SERIALIZE 0
#define APR_USE_SYSVSEM_SERIALIZE 1
#define APR_USE_POSIXSEM_SERIALIZE 0
#define APR_USE_FCNTL_SERIALIZE 0
#define APR_USE_PROC_PTHREAD_SERIALIZE 0
#define APR_USE_PTHREAD_SERIALIZE 1
// apr-1.7.0
#define APR_USE_FLOCK_SERIALIZE 0
#define APR_USE_SYSVSEM_SERIALIZE 0
#define APR_USE_POSIXSEM_SERIALIZE 0
#define APR_USE_FCNTL_SERIALIZE 0
#define APR_USE_PROC_PTHREAD_SERIALIZE 1
#define APR_USE_PTHREAD_SERIALIZE 1
可知,该报错的原因是新版本 apr 使用了 APR_USE_PROC_PTHREAD_SERIALIZE
,而不是 APR_USE_SYSVSEM_SERIALIZE
,两者的区别、优劣此处不作分析,下面说说解决方法。
方法1
在 httpd 中 configure 后,手动修改 apr/include/apr.h
文件。
方法2
在 httpd 中 configure 时,指定 apr_lock_method=USE_SYSVSEM_SERIALIZE
。
问题2:error: expat.h: No such file or directory
xml/apr_xml.c:35:10: fatal error: expat.h: No such file or directory
#include <expat.h>
^~~~~~~~~
compilation terminated.
/home/www/Desktop/appshmc_sd/with_hf/apache/httpd-2.4.46/srclib/apr-util/build/rules.mk:206: recipe for target 'xml/apr_xml.lo' failed
该问题由 apr-util 导致,从 missing expat with apr-util 1.6 中得知该版本移除了 expat,apr-util-1.6.0 及较新版本会报该错,对比 apr-util-1.3.12 和 apr-util-1.6.0 中的 xml 目录可以确认。
方法
(Ubuntu 中安装 libexpat1-dev,CentOS 中安装 expat-devel,只适应于本地编译,交叉编译仍会报错。此处有误请指正!)
交叉编译 expat。
cd expat-2.3.0
./configure \
--prefix=/home/www/Desktop/appshmc_sd/with_hf/apache/expat-2.3.0/install \
--host=arm-linux-gnueabihf \
CC=arm-linux-gnueabihf-gcc \
CXX=arm-linux-g++ \
--enable-shared --enable-static
make && make install
在 httpd 中 configure 时,指定 expat 的安装目录, --with-expat=/home/www/Desktop/appshmc_sd/with_hf/apache/expat-2.3.0/install
,注意必须是绝对路径。