ARM板 web服务器交叉编译及配置

httpd

一、apr 安装

1、解压

  • tar -xvf apr-1.7.0.tar.bz2

2、编译

./configure CC=aarch64-linux-gnu-gcc --host=aarch64-linux-gnu --prefix=/usr/local/apr  ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes apr_cv_process_shared_works=yes apr_cv_mutex_robust_shared=yes apr_cv_tcp_nodelay_with_cork=yes ap_void_ptr_lt_long=no 

参数说明

①如果不添加ac_cv_file__dev_zero=yes(注意file和dev之间是两个下划线),则会出现错误:

  • check for /dev/zero... configure:error:cannot check for file existence when cross compile

②如果不添加ac_cv_func_setpgrp_void=yes,则会出现错误:

  • checking whether setpgrp takes no argument... configure: error: cannot check setpgrp when cross compiling

③如果不添加apr_cv_process_shared_works、apr_cv_mutex_robust_shared、apr_cv_tcp_nodelay_with_cork则会出现如下错误:

  • 如果不写入第一项,则会出现错误:

    checking for working PROCESS_SHARED locks... configure:error: in `.../apr-1.4.6':
    

configure:error: cannot run test program while cross compiling

See `config.log' for more details
```

  • ​ 如果不写入第二项,则会出现:
checking for robust cross-process mutex support... configure: error: in `.../apr-1.4.6':

configure: error: cannot run test program while cross compiling

See `config.log' for more details
2.1、报错./include/apr_want.h:94:8: error: redefinition of 'struct iovec'

解决:vi include/apr_want.h

在编译的过程中会提示“iovec定义重复”在/apr/include目录。修改apr_want.h文件。将

 #ifndef APR_IOVEC_DEFINED
  #define APR_IOVEC_DEFINED
  struct iovec
 {
 void *iov_base;
  size_t iov_len;
  };  
  #endif /* !APR_IOVEC_DEFINED */
改为
  #if  0
 struct iovec
 {
 void *iov_base;
  size_t iov_len;
  };  
  #endif /* !APR_IOVEC_DEFINED */
2.2、报错encoding/apr_escape.c:79:33: error: ‘test_char_table’ undeclared
tools/gen_test_char > include/private/apr_escape_test_char.h 
/bin/bash: tools/gen_test_char: cannot execute binary file: Exec format error

原因:

因为gen_test_char 使用编译工具编译出来的,但交叉编译出的gen_test_char这个工具在宿主机上无法使用,
所以可以先./configure 再make 将工具保存起来 在执行交叉编译configure,再把工具cp回原位置并修改makefile 执行即解决

3、完整编译流程

1 ./configure
2 Make
3 cp -a tools/gen_test_char ..
4 Make clean
5 ./configure CC=aarch64-linux-gnu-gcc --host=aarch64-linux-gnu --prefix=/usr/local/apr  ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes apr_cv_process_shared_works=yes apr_cv_mutex_robust_shared=yes apr_cv_tcp_nodelay_with_cork=yes ap_void_ptr_lt_long=no 
6 cp -a ../gen_test_char tools/
7 Vi Makefile 
134 行
 OBJECTS_gen_test_char = tools/gen_test_char.lo $(LOCAL_LIBS)
屏蔽
 #OBJECTS_gen_test_char = tools/gen_test_char.lo $(LOCAL_LIBS) 
目的是不生成新的gen_test_char文件
8 vi include/apr_want.h 删除第 92 行 第93 #ifndef APR_IOVEC_DEFINED 替换成#if 0
9 make && make install

二、apr-util安装

先交叉编译libexpat,否则会报如下错误
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/root/package/apr-util-1.6.1'
make: *** [all-recursive] Error 1
编译过程

下载expat二进制包 [https://sourceforge.net/projects/expat/files/expat/2.2.9/expat-2.2.9.tar.xz/download]

tar -xvf expat-2.2.9.tar.xz
cd expat-2.2.9
./configure CC=aarch64-linux-gnu-gcc --host=aarch64-linux-gnu --prefix=/usr/local/expat
make && make install

1、编译

./configure CC=aarch64-linux-gnu-gcc --host=aarch64-linux-gnu --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr --with-expat=/usr/local/expat

make && make install

如下成功:

{{uploading-image-817344.png(uploading...)}}

三、httpd安装

注意:在对httpd进行arm交叉编译前,需要进行一次常规编译,执行到 make 后即可,无需执行make install。

原因:因为宿主机上无法运行使用交叉编译链编译的程序的缘故

将常规编译在httpd安装包生成的server文件夹拷出,留作后续使用。

tip:常规编译及交叉编译包不要弄混。

1、解压

tar -xvf httpd-2.4.43.tar.gz
cd  httpd-2.4.43

2、编译

./configure --prefix=/usr/local/mawbd --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --host=aarch64-linux-gnu CC=aarch64-linux-gnu-gcc  ap_cv_void_ptr_lt_long=no --enable-so --enable-cgi LDFLAGS=-lpthread
make
2.1 错误

①如果不添加ap_cv_void_ptr_lt_long=no选项,则会出现:

configure: error: Size of "void *" is less than size of "long"

②在执行过./configure指令后,进入httpd-2.4.3目录下的server目录中,修改一下其中的Makefile文件,找到如下行:

 test_char.h: gen_test_char

       ./gen_test_char > test_char.h

修改为

test_char.h: gen_test_char

       #./gen_test_char > test_char.h

保存后,将常规编译产出的server包导入到该环境的任意位置,切记不要放置在http的下。

然后找到server中的可执行程序gen_test_char,然后执行 ./gen_test_char > test_char.h

接下来make && make install 就不会报错了

如果不做上面任何修改,则会出现以下错误:

./gen_test_char > test_char.h
/bin/sh: ./gen_test_char: cannot execute binary file

至此apache在arm上交叉编译就完成了,可以通过file去检测httpd

原文地址:https://www.cnblogs.com/jmtang/p/13572318.html