交叉编译 nginx

thinks http://www.cppblog.com/van201314/articles/165661.html


HOST: ubuntu 12.04 LTS

NGINX VERSION: nginx-1.5.8

ZLIB VERSION: zlib-1.2.8

PCRE VERSION: pcre-8.20



1.auto/cc/name
    if [ "$NGX_PLATFORM" != win32 ]; then

    ngx_feature="C compiler"
    ngx_feature_name=
    #ngx_feature_run=yes
    ngx_feature_run=no   ==>set to no to skip check
    ngx_feature_incs=
    ngx_feature_path=

2.auto/types/sizeof
    ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS
    ==> ngx_test="gcc $CC_TEST_FLAGS $CC_AUX_FLAGS
    
3.src/os/unix/ngx_errno.h
at line 15 add #define NGX_SYS_NERR 333


4.src/os/unix/ngx_errno.c
#if (NGX_HAVE_MAP_ANON) ==> #if (!NGX_HAVE_MAP_ANON)

5.prepare zlib and pcre
    download zlib-1.2.8 and decompress to /home/mo/zlib-1.2.8
    download pcre-8.20 and decompress to /home/mo/pcre-8.20
6.auto/lib/pcre/make
    ./configure --disable-shared $PCRE_CONF_OPT
    ==>./configure --disable-shared $PCRE_CONF_OPT --host=arm
7.write a configure script
#!/bin/sh
BUILD_PATH=/home/mo/nginx-1.5.8/arm-build
CC_PATH=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-gcc
CPP_PATH=/opt/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-g++
./configure \
  --prefix=$BUILD_PATH \
  --user=root \
  --group=root \
  --builddir=$BUILD_PATH\build \
  --with-zlib=/home/mo/zlib-1.2.8 \
  --with-pcre \
  --with-pcre=/home/mo/pcre-8.20 \
  --with-pcre-jit \
  --with-cc=$CC_PATH  \
  --with-cpp=$CPP_PATH

save to my_configure.sh

8.start to compile
./my_configure.sh
make
make install

9.copy the install dir arm_build to the board(like /home/app/nginx),and run link this
/home/app/nginx/sbin/nginx -p /home/app/nginx



下面是修改好的代码的链接:

http://download.youkuaiyun.com/detail/crazyman2010/8311117

交叉编译 Nginx 是一种在当前平台上(例如 x86 架构)生成适用于不同架构或操作系统(如 ARM 或嵌入式系统)的可执行文件的方法。以下是详细的步骤和注意事项: ### 交叉编译的基本流程 1. **准备工具链** 在开始之前,确保已安装目标平台所需的交叉编译工具链。例如,若要为 ARM 平台编译,则需要使用 `arm-linux-gnueabihf-gcc` 工具链: ```bash sudo apt-get install gcc-arm-linux-gnueabihf ``` 这一步是基础,因为缺少合适的编译器将无法进行后续操作 [^2]。 2. **下载 Nginx 源码** 下载与需求兼容的 Nginx 源代码包,通常可以从官方网站获取最新版本。 3. **配置编译选项** 使用 `./configure` 脚本来指定交叉编译参数及模块支持。以下是一个典型的配置命令示例: ```bash ./configure --prefix=/usr/local/nginx \ --crossbuild=ARM \ --host=arm-linux \ --with-cc=arm-linux-gnueabihf-gcc \ --with-zlib=/path/to/zlib \ --with-pcre=/path/to/pcre \ --with-openssl=/path/to/openssl \ --with-http_ssl_module \ --with-http_mp4_module \ --with-http_v2_module \ --without-http_upstream_zone_module \ --add-module=/path/to/additional/module \ --with-cpp=/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \ --with-ld-opt=-pthread ``` 上述命令中包含了多个选项,其中 `--crossbuild=ARM` 和 `--host=arm-linux` 表明了目标架构,而 `--with-cc=arm-linux-gnueabihf-gcc` 则指定了具体的编译器路径 [^1]。 4. **依赖库的准备** 确保所有依赖库(如 zlib、PCRE 和 OpenSSL)都已正确下载并解压至指定位置,并且这些库也应通过交叉编译方式构建以匹配目标平台 [^3]。 5. **执行编译** 配置完成后,运行 `make` 命令来编译 Nginx: ```bash make && make install ``` 6. **测试与部署** 编译成功后,将生成的二进制文件复制到目标设备上进行测试。需要注意的是,在目标设备上可能还需要额外的环境配置才能保证 Nginx 正常运行。 ### 注意事项 - **工具链选择**:根据目标平台的不同,可能需要不同的工具链。Linaro 提供了一系列针对 ARM 架构优化的 GCC 工具链,可以作为首选 [^3]。 - **依赖库版本一致性**:确保所使用的第三方库版本与 Nginx 兼容,避免因版本差异导致的问题。 - **静态链接 vs 动态链接**:考虑是否需要静态链接某些库,这有助于减少目标系统的依赖项要求 [^2]。 - **文档参考**:查阅相关帮助文档,了解更详细的配置指南和技术细节 [^4]。 ###
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值