从零开始 Nginx 交叉编译

交叉编译工具链: arm-poky-linux-gnueabi-gcc 

 

./configure --prefix=/home/chad/Documents/nginx_cr  --with-cc=arm-poky-linux-gnueabi-gcc

出现如下的问题

root@ubuntu:/home/chad/Downloads/nginx-1.18.0# ./configure --prefix=/home/chad/Documents/nginx_cr  --with-cc=arm-poky-linux-gnueabi-gcc
checking for OS
 + Linux 4.15.0-101-generic x86_64
checking for C compiler ... not found

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

 

src/core/ngx_rwlock.c:125:2: error: #error ngx_atomic_cmp_set() is not defined!
 #error ngx_atomic_cmp_set() is not defined!
  ^
objs/Makefile:547: recipe for target 'objs/src/core/ngx_rwlock.o' failed
make[1]: *** [objs/src/core/ngx_rwlock.o] Error 1
make[1]: Leaving directory '/home/chad/Downloads/nginx-1.18.0'
Makefile:8: recipe for target 'build' failed
make: *** [build] Error 2

解决办法,在configure的时候加上--without-http_upstream_zone_module

src/os/unix/ngx_errno.c: In function 'ngx_strerror':
src/os/unix/ngx_errno.c:37:31: error: 'NGX_SYS_NERR' undeclared (first use in this function)
     msg = ((ngx_uint_t) err < NGX_SYS_NERR) ? &ngx_sys_errlist[err]:
                               ^
src/os/unix/ngx_errno.c:37:31: note: each undeclared identifier is reported only once for each function it appears in
src/os/unix/ngx_errno.c: In function 'ngx_strerror_init':
src/os/unix/ngx_errno.c:58:11: error: 'NGX_SYS_NERR' undeclared (first use in this function)
     len = NGX_SYS_NERR * sizeof(ngx_str_t);
           ^
objs/Makefile:664: recipe for target 'objs/src/os/unix/ngx_errno.o' failed
make[1]: *** [objs/src/os/unix/ngx_errno.o] Error 1
make[1]: Leaving directory '/home/chad/Downloads/nginx-1.18.0'
Makefile:8: recipe for target 'build' failed
make: *** [build] Error 2

出错的原因仍然是因为交叉编译程序无法本地运行,导致NGX_SYS_NERR宏没有赋值。解决办法,手动编辑 objs/ngx_auto_config.h,加上

#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR  132
#endif

 

Nginx是一个开源的高性能Web服务器和反向代理服务器,常用于构建动态网站、负载均衡以及缓存等应用场景。交叉编译是指在一台主机上编译生成能够在另一种平台上运行的可执行文件。下面是关于Nginx交叉编译的一些详细信息。 交叉编译Nginx有以下几个步骤: 1. 准备交叉编译工具链:由于编译目标平台与主机平台不一致,需要准备交叉编译工具链。工具链是由交叉编译器、库文件以及其他工具组成的集合,用于在主机上编译生成目标平台的可执行文件。根据目标平台的不同,可以使用不同的交叉编译工具链。 2. 配置Nginx的编译选项:在进行交叉编译之前,需要根据目标平台的需求来配置Nginx的编译选项。这些选项包括目标平台的体系结构、操作系统、编译器等信息。 3. 执行交叉编译命令:在完成工具链的准备和Nginx的配置后,可以执行交叉编译命令来生成目标平台上运行的Nginx可执行文件。交叉编译命令一般会使用到之前准备的交叉编译工具链。 4. 测试和部署:在成功编译生成Nginx可执行文件后,可以在目标平台上进行测试和部署。测试可以验证编译生成的Nginx是否能够在目标平台上正常运行,部署则是将编译生成的Nginx安装到目标平台的指定位置,以便进行实际的应用。 总之,通过交叉编译可以在一台主机上为不同的目标平台生成可执行文件,这为Nginx在不同平台上的部署和使用提供了便利。交叉编译Nginx需要准备交叉编译工具链、配置编译选项,然后执行交叉编译命令来生成目标平台上可运行的Nginx文件。最后,可以在目标平台上进行测试和部署。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值