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个新问题及解决方法。

注意:

  1. 如果选择 apr-1.4.5 、apr-util-1.3.12,则不会遇到下述问题,奈何本人有更新强迫症。
  2. 请根据实际情况修改路径、工具链。

环境

截至 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.52012-02-14apr-util-1.3.122011-05-20通过
apr-1.7.02020-07-06apr-util-1.3.122011-05-20通过,apr_lock_method=USE_SYSVSEM_SERIALIZE
apr-1.7.02020-07-06apr-util-1.4.12011-12-13通过,apr_lock_method=USE_SYSVSEM_SERIALIZE
apr-1.7.02020-07-06apr-util-1.5.42014-09-20通过,apr_lock_method=USE_SYSVSEM_SERIALIZE
apr-1.7.02020-07-06apr-util-1.6.02017-06-12通过,expat.h,XML_xxx,–with-expat
apr-1.7.02020-07-06apr-util-1.6.12020-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,注意必须是绝对路径。

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值