• Apache 2 移植到Arm开发板


    第一步,安装pcre

    tar -xvzf pcre-8.31.tar.gz

    cd pcre-8.31

    ./configure --prefix=$ARMROOTFS/usr/pcre --host=arm-linux CC=$TOOLCHAIN/arm-linux-gcc CXX=$TOOLCHAIN/arm-linux-g++ LD=$TOOLCHAIN/arm-linux-ld

    make

    make install

    第二步,安装apr

    这里特别提醒,先看一下后面的几点一些要注意的地方,特别是第⑤点

    tar -xvzf apr-1.4.6.tar.gz

    cd apr-1.4.6

    ./configure --prefix=$ARMROOTFS/usr/apr --host=arm-linux CC=$TOOLCHAIN/arm-linux-gcc CXX=$TOOLCHAIN/arm-linux-g++ LD=$TOOLCHAIN/arm-linux-ld ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes apr_cv_tcp_nodelay_with_cork=yes --cache=arm-linux.cache

    这里简要说明一下如果不添加某些选项会出现的错误提示及一些需要特别注意的地方(这里按照我所记录的错误出现的顺序说明,而不是按上面选项的顺序):

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

    check for /dev/zero... configureerrorcannot 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

    的错误,如下图:

    ③选项--cache=arm-linux.cache中,arm-linux.cache为自己建立编写的文件(在编译过程中内容会被修改),在建立时需要自己写入如下内容:

    apr_cv_process_shared_works=yes

    apr_cv_mutex_robust_shared=yes

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

    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

    的错误,如下图:

    这些错误产生的原因在于这里在configure运行配置的过程中要运行几个测试程序来检验一些配置(个人理解),但在此处指定了编译时采用的编译器是交叉编译链,这几个测试程序都是经过交叉编译链编译产生的,而在宿主机系统上无法运行这些程序,因此只好自己手动指定这些检测程序最后运行的结果。

    在以后为开发板配置软件包时遇到这种错误:configure:error:cannot run test program while cross compiling,应该都可以通过这种方法解决。

    那么如果查找出这些表示结果的变量呢?只要在configure文件中搜寻这些错误的关键字即可,如这里的第一个项,我们可以搜寻:working PROCESS_SHARED locks,然后在configure文件中可以锁定到如下代码段:

    ...

          { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working PROCESS_SHARED locks" >&5

    $as_echo_n "checking for working PROCESS_SHARED locks... " >&6; }

    if ${apr_cv_process_shared_works+:} false; then :

      $as_echo_n "(cached) " >&6

    else

    ...

    这里可以看出变量apr_cv_process_shared_works便是与这个程序运行结果关联的变量。

    ④如果不添加ac_cv_sizeof_struct_iovec=8选项,则会在使用make指令时出现:

    ./include/apr_want.h:95: error: redefinition of 'struct iovec'

    make[1]: *** [passwd/apr_getpass.lo] 错误 1

    的错误,如下图:

    ⑤在添加了ac_cv_sizeof_struct_iovec=8选项后,还需要对configure文件进行一下修改,搜索apr_ssize_t可以定位到下面一段代码:

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking which format to use for apr_ssize_t" >&5

    $as_echo_n "checking which format to use for apr_ssize_t... " >&6; }

    if test -n "$ssize_t_fmt"; then

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %$ssize_t_fmt" >&5

    $as_echo "%$ssize_t_fmt" >&6; }

    elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_int"; then

        ssize_t_fmt="d"

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %d" >&5

    $as_echo "%d" >&6; }

    elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_long"; then

        ssize_t_fmt="ld"

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %ld" >&5

    $as_echo "%ld" >&6; }

    else

        as_fn_error $? "could not determine the proper format for apr_ssize_t" "$LINENO" 5

    fi

    将中间添加一段代码(红色标注),修改为

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking which format to use for apr_ssize_t" >&5

    $as_echo_n "checking which format to use for apr_ssize_t... " >&6; }

    if test -n "$ssize_t_fmt"; then

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %$ssize_t_fmt" >&5

    $as_echo "%$ssize_t_fmt" >&6; }

    elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_int"; then

        ssize_t_fmt="d"

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %d" >&5

    $as_echo "%d" >&6; }

    elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_long"; then

        ssize_t_fmt="ld"

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %ld" >&5

    $as_echo "%ld" >&6; }

    elif test "$ac_cv_sizeof_ssize_t" = "$ac_cv_sizeof_long_long";then

        ssize_t_fmt="lld"

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %lld" >&5

    $as_echo "%lld" >&6; }

    else

        as_fn_error $? "could not determine the proper format for apr_ssize_t" "$LINENO" 5

    fi

    搜索apr_size_t可以定位到下面一段代码

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking which format to use for apr_size_t" >&5

    $as_echo_n "checking which format to use for apr_size_t... " >&6; }

    if test -n "$size_t_fmt"; then

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %$size_t_fmt" >&5

    $as_echo "%$size_t_fmt" >&6; }

    elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_int"; then

        size_t_fmt="d"

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %d" >&5

    $as_echo "%d" >&6; }

    elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_long"; then

        size_t_fmt="ld"

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %ld" >&5

    $as_echo "%ld" >&6; }

    else

        as_fn_error $? "could not determine the proper format for apr_size_t" "$LINENO" 5

    fi

    将中间添加一段代码(红色标注),修改为:

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking which format to use for apr_size_t" >&5

    $as_echo_n "checking which format to use for apr_size_t... " >&6; }

    if test -n "$size_t_fmt"; then

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %$size_t_fmt" >&5

    $as_echo "%$size_t_fmt" >&6; }

    elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_int"; then

        size_t_fmt="d"

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %d" >&5

    $as_echo "%d" >&6; }

    elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_long"; then

        size_t_fmt="ld"

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %ld" >&5

    $as_echo "%ld" >&6; }

    elif test "$ac_cv_sizeof_size_t" = "$ac_cv_sizeof_long_long"; then

        size_t_fmt="lld"

        { $as_echo "$as_me:${as_lineno-$LINENO}: result: %lld" >&5

    $as_echo "%lld" >&6; }

    else

        as_fn_error $? "could not determine the proper format for apr_size_t" "$LINENO" 5

    fi

    如果什么修改也不做,则会出现:

    checking which format to use for apr_ssize_t... configure:error:could not determine the proper format for apr_ssize_t

    的错误,如下图:

    如果只做了第一个修改,则会出现:

    checking which format to use for apr_size_t... configure:error:could not determine the proper format for apr_size_t

    的错误,如下图:

    这是apr源代码包本身有的bug,这样修改后,在最后编译httpd时,会出现一些warning,大概意思是说参数类型为pid_t的地方,出现的参数类型为long long,但pid_t的类型本身就是unsigned int,因此应该是没有问题的。

    第三步,安装apr-util

    tar -xvzf apr-util-1.4.1.tar.gz

    cd apr-util-1.4.1

    ./configure

    ./configure --prefix=$ARMROOTFS/usr/local/apr-util --with-apr=$ARMROOTFS/usr/local/apr --host=arm-linux CC=$TOOLCHAIN/arm-linux-gcc CXX=$TOOLCHAIN/arm-linux-g++ LD=$TOOLCHAIN/arm-linux-ld 

    make

    make install

    第四步,安装httpd

    这里提醒一下先看一下后面的几点要注意的地方,特别是第②点

    tar -xvzf httpd-2.4.3.tar.gz

    cd httpd-2.4.3

    ./configure --prefix=$ARMROOTFS/etc/apache --with-pcre=$ARMROOTFS/usr/local/pcre --with-apr=$ARMROOTFS/usr/local/apr --with-apr-util=$ARMROOTFS/usr/local/apr-util --host=arm-linux CC=$TOOLCHAIN/arm-linux-gcc CXX=$TOOLCHAIN/arm-linux-g++ LD=$TOOLCHAIN/arm-linux-ld ap_cv_void_ptr_lt_long=no --enable-so --enable-cgi LDFLAGS=-lpthread

    make DESTDIR=$ARMROOTFS

    make install

    在编译过程中要注意以下几点:

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

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

    的错误,如下图:

    ②在执行过./configure指令后,在为开发板编译httpd执行make命令前,需要先对宿主机上编译过一次httpd(即至少执行到makemake install可不执行,宿主机上不最终安装apache2也是可以的),然后到为开发板编译httpdhttpd-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

    $httpd_for_pc/server/gen_test_char > test_char.h

    其中这里的变量httpd_for_pc只是指代为宿主机编译的httpd软件包加压后的文件夹路径。

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

    ./gen_test_char > test_char.h

    /bin/bash: ./gen_test_char: 无法执行二进制文件

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

    如果只修改为:

    test_char.h: gen_test_char

    #./gen_test_char > test_char.h

    而在宿主机上不编译一次httpd,则会出现以下错误:

    util.c: In function 'ap_find_token':

    util.c:1434: error: 'test_char_table' undeclared (first use in this function)

    util.c:1434: error: (Each undeclared identifier is reported only once

    util.c:1434: error: for each function it appears in.)

    util.c:1434: error: 'T_HTTP_TOKEN_STOP' undeclared (first use in this function)

    util.c: In function 'ap_escape_shell_cmd':

    util.c:1498: error: 'test_char_table' undeclared (first use in this function)

    util.c:1498: error: 'T_ESCAPE_SHELL_CMD' undeclared (first use in this function)

    util.c: In function 'ap_escape_path_segment_buffer':

    util.c:1706: error: 'test_char_table' undeclared (first use in this function)

    util.c:1706: error: 'T_ESCAPE_PATH_SEGMENT' undeclared (first use in this function)

    util.c: In function 'ap_os_escape_path':

    util.c:1740: error: 'test_char_table' undeclared (first use in this function)

    util.c:1740: error: 'T_OS_ESCAPE_PATH' undeclared (first use in this function)

    util.c: In function 'ap_escape_urlencoded_buffer':

    util.c:1759: error: 'test_char_table' undeclared (first use in this function)

    util.c:1759: error: 'T_ESCAPE_URLENCODED' undeclared (first use in this function)

    util.c: In function 'ap_escape_logitem':

    util.c:1844: error: 'test_char_table' undeclared (first use in this function)

    util.c:1844: error: 'T_ESCAPE_LOGITEM' undeclared (first use in this function)

    util.c: In function 'ap_escape_errorlog_item':

    util.c:1896: error: 'test_char_table' undeclared (first use in this function)

    util.c:1896: error: 'T_ESCAPE_LOGITEM' undeclared (first use in this function)

    util.c: In function 'ap_append_pid':

    这里就不截图了。可见./gen_test_char > test_char.h这条语句是为了生成一些宏定义或者全局变量到test_char.h这个头文件中去,而里面这些宏定义和全局变量又在httpd源程序的中使用到。因此宿主机系统也必须编译一次httpd才可以完成开发板安装apache2服务器软件。

    如果在执行上面的修改前执行过一次make,那么需要执行make clean命令后,再执行make才能编译通过。

    经过以上步骤后,进入开发板文件系统目录,修改etc/apache/bin目录下的apachectl文件,搜索HTTPD,可以找到该变量,将该变量的值修改为:HTTPD='/etc/apache/bin/httpd'

    为了方便以后在开发板上输入打开和关闭apache2服务器的指令,可以执行以下命令:

    sudo cp $ARMROOTFS/etc/httpd/bin/apachectl $ARMROOTFS/usr/sbin/

    sudo cp $ARMROOTFS/etc/httpd/bin/apachectl $ARMROOTFS/etc/init.d/

    第五步:复制共享库(为宿主机系统编译安装apache2不需要进行这一步)

    之后还需要复制一些共享库到开发板文件系统的/usr/lib目录下,否则会启动不了apache2服务器,像以下错误:

    ①error while loading shared libraries: libpcre.so.1:cannot open shared object file:No such file for directory

    解决方法:cp $ARMROOTFS/usr/local/pcre/lib/libpcre.so* $ARMROOTFS/usr/lib

    ②error while loading shared libraries: libaprutil-1.so.0:cannot open shared object file:No such file for directory

    解决方法:cp $ARMROOTFS/usr/local/apr-util/lib/libaprutil-1.so* $ARMROOTFS/usr/lib

    ③error while loading shared libraries: libexpat.so.0:cannot open shared object file:No such file for directory

    解决方法:cp $ARMROOTFS/usr/local/apr-util/lib/libexpat.so* $ARMROOTFS/usr/lib

    ④error while loading shared libraries: libapr-1.so.0:cannot open shared object file:No such file for directory

    解决方法:cp $ARMROOTFS/usr/local/apr/lib/libapr-1.so* $ARMROOTFS/usr/lib

    ⑤error while loading shared libraries: libuuid.so.1:cannot open shared object file:No such file for directory

    解决方法:需要编译一次e2fsprogs这个软件包,使它生成这个共享库。

    tar -xvzf e2fsprogs-1.42.8.tar.gz

    cd e2fsprogs-1.42.8

    ./configure --prefix=$ARMROOTFS/usr/local/e2fsprogs --host=arm-linux CC=$TOOLCHAIN/arm-linux-gcc LD=$TOOLCHAIN/arm-linux-ld --enable-elf-shlibs

    make

    make install(可以不执行这一步)

    之后在软件包加压后的e2fsprogs-1.42.8目录下执行:

    cp lib/libuuid.so* $ARMROOTFS/usr/lib/

    第六步及之后:还没有解决的问题

    本人经过上面的编译安装后,在开发板进入系统后,执行apachectl指令,仍然未能成功启动apache服务器,系统提示错误为:

    AH00141Could not initialize random number generator

  • 相关阅读:
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
  • 原文地址:https://www.cnblogs.com/zhangsf/p/3272960.html
Copyright © 2020-2023  润新知