交叉编译nginx1.20.0

发布于:2024-08-09 ⋅ 阅读:(171) ⋅ 点赞:(0)

一、说明

        简略写一下过程,仅用于参考,建议与其他交叉编译教程一起看,检查是否有遗漏的问题。

二、源码修改

1、auto/cc/name
vi auto/cc/name

        注释 21 行 exit 1。

2、auto/types/sizeof
vi auto/types/sizeof

将 15 行处的” ngx_size=”修改为” ngx_size=4”
将 36 行处的”$CC”修改为”gcc”
将 44 行注释,添加45行” ngx_size=4”

三、下载源码

        注意,需要下载openssl、pcre以及zlib源码,我使用的版本:

能够成功编译,下载方式可百度。

以及nginx-rtmp-module:

git clone https://github.com/arut/nginx-rtmp-module.git

四、配置configure

configure配置命令:(注意不能直接复制使用)

./configure --prefix=/home/ds-admin/tools/nginx/arm32
--with-cc=arm-linux-gnueabihf-gcc 
--with-cpp=arm-linux-gnueabihf-cpp  
--with-http_mp4_module 
--with-http_v2_module 
--without-http_upstream_zone_module 
--add-module=/home/ds-admin/tools/nginx/nginx-rtmp-module
--with-http_ssl_module 
--with-openssl=/home/ds-admin/tools/openssl/openssl-1.1.1f 
--with-pcre=/home/ds-admin/tools/pcre/pcre-8.45 
--with-zlib=/home/ds-admin/tools/zlib/zlib-1.3.1

我没有用换行符拼接,需要逐一复制,参数意义大概都能看懂。

需要修改交叉编译器以及安装路径。

五、Makefile修改

        需要继续修改Makefile文件,打开obj/Makefile。

1、pcre-8.45/Makefile:

在--disable-shared后面添加--host选项,根据自己交叉编译器修改。

2、openssl:

网上有很多教程,我融合了多个方法做了一个拼接,不一定适用所有版本!

首先进入openssl源码下,配置config,没有使用configure,

./config no-asm shared no-async --prefix=$(pwd)/.openssl --cross-compile-prefix=arm-linux-gnueabihf-

这里将安装目录设置为.openssl是因为nginx默认的安装目录,不去修改减少麻烦。

打开Makefile:

将PLATFORM改为arm。

往下找到FLAGS,删除两个 -m64:

退出,先不执行make。

返回nginx源码目录,打开obj/Makefile,找到

删除config配置,改为:

3、增加 -pthread 链接

搜索libpcre.a,找到编译选项,在-ldl -lcrypt后添加 -pthread:

六、编译

        返回nginx源码目录,执行make -j8,要么 make -j4。

肯定报错,但是需要执行才能修改下一步:

修改objs/nginx_auto_config.h:

vi objs/nginx_auto_config.h
#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif

将上述宏定义添加到头文件,保存后重新make。

此时源码/obj下已经成功编译了nginx:

该可执行文件还未strip:

执行strip,用来去除目标文件中的一些符号表、调试符号表信息,以减小程序的大小:

arm-linux-gnueabihf-strip nginx


网站公告

今日签到

点亮在社区的每一天
去签到