nginx交叉编译

这里记录一下所遇到的问题。

  1. 下载pcre,openssl,nginx源码解压到同级目录。

  2. 配置环境变量:
    export INSTALL_PATH=/usr/local/nginx //安装路径会写入nginx可执行程序
    export CC_PATH=/var/gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/aarch64-linux-gnu-gcc
    export CPP_PATH=/var/gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/aarch64-linux-gnu-g++

  3. 配置configure:

     ./configure --prefix=$INSTALL_PATH  \
     --without-http_gzip_module \					
     --without-http_upstream_zone_module \			
     --with-http_ssl_module \						
     --with-pcre=/home/pcre-8.36 \
     --with-zlib=/home/zlib-1.2.7 \
     --with-openssl=/home/openssl-1.0.2s \
     --with-cc=$CC_PATH \
     --with-cpp=$CPP_PATH
    
  4. 编译:

    make;make install

    遇到的问题

    这里补上漏掉的问题:

configure错误:
1

checking for C compiler ... found but is not working

./configure: error: C compiler arm-hisiv400-linux-gcc is not found

vi auto/cc/name ,找到

if [ $ngx_found = no ]; then
        echo
        echo $0: error: C compiler $CC is not found
        echo
        exit 1
    fi

configure首先会编译一个小测试程序,通过测试其运行结果来判断编译器是否能正常工作,由于交叉编译器所编译出的程序是无法在编译主机上运行的,故而产生此错误。exit 1 注释掉。

2

autotest:Syntax error: Unterminated quoted string bytes 
./configure : error:can not detect int size

vi auto/types/sizeof ,
ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS
改为
ngx_test="gcc $CC_TEST_FLAGS $CC_AUX_FLAGS

make错误:
3
src/core/ngx_rwlock.c:125:2: error: #error ngx_atomic_cmp_set() is not defined!
这个错误需要将 configure时 加入–without-http_upstream_zone_module参数。

1pcre没有指定host。在nginx/objs/Makefile 修改

/home/pcre-8.36/Makefile:       objs/Makefile
        cd /home/pcre-8.36 \
        && if [ -f Makefile ]; then $(MAKE) distclean; fi \        
        && CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
        ./configure --disable-shared

最后一行增加 --host=aarch64-linux-gnu

2
在这里插入图片描述
看提示是在unix系统openssl需要使用config而不是Configure。修改nginx/objs/Makefile

/home/openssl-1.0.2s/.openssl/include/openssl/ssl.h:    objs/Makefile
        cd /home/openssl-1.0.2s \
        && if [ -f Makefile ]; then $(MAKE) clean; fi \
        && ./Configure --prefix=/home/openssl-1.0.2s/.openssl no-shared no-threads --cross-compile-prefix=/var/gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/aarch64-linux-gnu- \
        && $(MAKE) \
        && $(MAKE) install_sw LIBDIR=lib

将Configure改为config。

3 在这里插入图片描述
-m64 是64位操作系统,但是不知道为什么我的编译器识别不了,所以只能到openssl文件夹单独编译openssl。需要删除openssl的Makefile中所有 -m64 的地方,有两处。SHARED_LDFLAGS=-m64这里整行删除。

4在这里插入图片描述
这个需要修改nginx/objs/Makefile , 第2个问题中config行增加 no-asm ,禁用汇编。重新make,再到openssl文件夹修改Makefile后make;make install,回到nginx文件夹重新make

5
在这里插入图片描述
需要修改 objs/ngx_auto_config.h,增加

#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR  132
#endif

在这里插入图片描述这个问题需要修改相同位置

#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif

make成功后make install 安装到设置的安装目录。

参考文章:
https://blog.youkuaiyun.com/fish43237/article/details/40515897
https://www.jianshu.com/p/5d9b60f7b262

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值