nginx 交叉编译

2023-11-18

环境:

Linux CentOS6.9 2.6.32-696.el6.x86_64

软件版本:

nginx http://nginx.org/download/nginx-1.18.0.tar.gz
openssl https://www.openssl.org/source/old/1.1.1/openssl-1.1.1f.tar.gz
zlib https://codeload.github.com/madler/zlib/tar.gz/refs/tags/v1.2.11
pcre https://nchc.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.gz

下载上面的软件包之后解压,可得:

.
├── nginx-1.18.0
├── openssl-1.1.1f
├── pcre-8.45
└── zlib-1.2.11

nginx 官方文档:http://nginx.org/en/docs/configure.html

生成 Makefile

编辑以下脚本(build.sh):

#!/bin/sh

# 该脚本放在 nginx-1.18.0 目录下执行

BUILD_PATH=$(pwd)
CROSS_CC=${你的编译器目录}/arm-buildroot-linux-gnueabi-

ZLIB_PATH=${BUILD_PATH}/../zlib-1.2.11
PCRE_PATH=${BUILD_PATH}/../pcre-8.45
OPENSSL_PATH=${BUILD_PATH}/../openssl-1.1.1f

./configure --prefix=${BUILD_PATH}/_install \
	--with-cc=${CROSS_CC}gcc \
	--with-cpp=${CROSS_CC}g++ \
	--with-cc-opt=-pthread \
	--without-http_upstream_zone_module \
	--with-cc-opt="-D_GNU_SOURCE" \
    --with-http_ssl_module \
	--with-pcre=${PCRE_PATH} \
    --with-zlib=${ZLIB_PATH} \
	--with-openssl=${OPENSSL_PATH} \
	--with-openssl-opt="linux-generic32"

解决报错

执行上面的脚本 (build.sh) 会出现以下报错:

错误1:checking for C compiler ... found but is not working

checking for OS
 + Linux 2.6.32-696.el6.x86_64 x86_64
checking for C compiler ... found but is not working

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

解决方法:

修改 auto/cc/name 文件如下(注释掉 21 行)

 错误2:./configure: error: can not detect int size

checking for int size ...auto/types/sizeof: line 43: objs/autotest: cannot execute binary file
  bytes

./configure: error: can not detect int size

解决方法:

编辑 auto/types/sizeof 文件如下(注释掉 17 到 31 行,并修改 ngx_size=4,32位目标平台是4,64位的话是8),修改后如下:

修改完上面 2 处错误后重新执行 build.sh,出现下图即可:

Configuration summary
  + using PCRE library: /home/chengc/nginx/nginx-1.18.0/../pcre-8.45
  + using OpenSSL library: /home/chengc/nginx/nginx-1.18.0/../openssl-1.1.1f
  + using zlib library: /home/chengc/nginx/nginx-1.18.0/../zlib-1.2.11

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

接下来执行 make,不出意外的话就会出现以下错误:

错误3 :pcre-8.45/Makefile] 错误 77

configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
make[1]: *** [/home/chengc/nginx/nginx-1.18.0/../pcre-8.45/Makefile] 错误 77
make[1]: Leaving directory `/home/chengc/nginx/nginx-1.18.0'
make: *** [build] 错误 2

解决方法1(推荐):修改 auto/options 文件中的 PCRE_CONF_OPT=--host=arm-buildroot-linux,然后重新执行 build.sh 脚本。

解决方法2: 修改 objs/Makefile,找到 pcre 部分,加上 --host

错误4:Failure!  build file wasn't produced.

Failure!  build file wasn't produced.
Please read INSTALL and associated NOTES files.  You may also have to look over
your available compiler tool chain or change your configuration.

target already defined - linux-x86_64 (offending arg: linux-generic32)
make[1]: *** [/home/chengc/nginx/nginx-1.18.0/../openssl-1.1.1f/.openssl/include/openssl/ssl.h] 错误 255
make[1]: Leaving directory `/home/chengc/nginx/nginx-1.18.0'

解决方法1(推荐):修改 auto/lib/openssl/make 文件如下,然后重新执行 build.sh 脚本。

​​​​​​​   

 解决方法2:修改 objs/Makefile,原文如下

修改 1242 行,将 ./config 改为 ./Configure CC=${CC} ,改后如下:

 错误5:'NGX_SYS_NERR' undeclared

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);
           ^
make[1]: *** [objs/src/os/unix/ngx_errno.o] 错误 1
make[1]: Leaving directory `/home/chengc/nginx/nginx-1.18.0'

解决方法:编辑 objs/ngx_auto_config.h,加入以下宏定义:

#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR  132
#endif

错误6:undefined reference to `ngx_shm_alloc'

objs/src/core/ngx_cycle.o: In function `ngx_init_cycle':
/home/chengc/nginx/nginx-1.18.0/src/core/ngx_cycle.c:476: undefined reference to `ngx_shm_alloc'
/home/chengc/nginx/nginx-1.18.0/src/core/ngx_cycle.c:685: undefined reference to `ngx_shm_free'
/home/chengc/nginx/nginx-1.18.0/src/core/ngx_cycle.c:902: undefined reference to `ngx_shm_free'
objs/src/event/ngx_event.o: In function `ngx_event_module_init':
/home/chengc/nginx/nginx-1.18.0/src/event/ngx_event.c:551: undefined reference to `ngx_shm_alloc'
collect2: error: ld returned 1 exit status
make[1]: *** [objs/nginx] 错误 1
make[1]: Leaving directory `/home/chengc/nginx/nginx-1.18.0'

解决方法:编辑 objs/ngx_auto_config.h,加入以下宏定义:

#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif

最后执行 make install

_install/
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── html
│   ├── 50x.html
│   └── index.html
├── logs
└── sbin
    └── nginx

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

nginx 交叉编译 的相关文章

随机推荐

  • Ansys workbench 云图如何不显示边框

    由于对workbench不熟悉 走了很多弯路 云图上有边框总是不好看 但是又不知道在哪里关掉它 经过一番摸索终于找到了 关闭前 关闭方法 工具栏 WireFrame 按钮 点一下即可 希望对有需要的朋友有用
  • 蓝桥杯:基础练习 特殊回文数(java实现)

    问题描述 123321是一个非常特殊的数 它从左边读和从右边读是一样的 输入一个正整数n 编程求所有这样的五位和六位十进制数 满足各位数字之和等于n 输入格式 输入一行 包含一个正整数n 输出格式 按从小到大的顺序输出满足条件的整数 每个整
  • MySQL 重命名表名 2种方法

    今天用 phpMyAdmin 创建了一张表后 发现 表名字 取得有点后悔 想直接删除重新创建一个 但是这个表的字段又有点多 居然有30多个字段 后来就找到了MySQL表重命名的方法 也可以说是MySQL修改表名称 先创建一张表 创建用户表
  • Navicat连接本地数据库,报错误:2059

    错误 使用Navicat Premium 连接MySQL时出现如下错误 原因 mysql8 之前的版本中加密规则是mysql native password 而在mysql8之后 加密规则是caching sha2 password 解决
  • 小程序云函数使用

    1 开通云开发 2 project config json 文件中加入配置 cloudfunctionRoot cloudFuction description 项目配置文件 cloudfunctionRoot cloudFuction 3
  • SSHUtil填写入参报错Too many characters in character literal

    当光标放到错误上面 提示Too many characters in character literal 翻译过来就是符字面量太多 解决方法 就是把单引号改成双引号就可以了 参考 https blog csdn net for him ar
  • 初级PHP工程师对于进阶的思考

    突然想写篇博客记录下刚毕业这段时间的经历 主要是对于人生的下一阶段的思考和诸多事物触起的思考 一 人生的下一阶段 人生的意义从来不是为自己奋斗 生活的意义也从来不是奋斗 今年毕业 距离博文发表的现在约莫有2个月 毕业前的我是一个极度执着追求
  • 四十六.冒泡排序C语言实现

    include
  • SeleniumLibrary4.5.0 关键字详解(七)

    SeleniumLibrary4 5 0 关键字详解 七 库版本 4 5 0 库范围 全局 命名参数 受支持 简介 SeleniumLibrary是Robot Framework的Web测试库 本文档说明了如何使用SeleniumLibra
  • FbxSDK使用总结

    Fbx文件结构太复杂 FbxSDK太难理解 Fbx官网文档功能介绍太不清晰 FbxSDK中的示例程序太冷门 太不解决问题 网络上找不到能够解决我的痛点的方法 有相同烦恼的不只我一个人 一个叫 Tianyu Lang 的歪果仁也发出抱怨 并怒
  • 常见芯片算力对比(一)

    常见芯片算力对比 一 Hi3559A 即Hi3559ARFCV100 4T算力 封装 FC BGA 常备 Hi3519A Hi3519ARFVV100 才是AI芯片 2T算力 kirin980 4 2TOPS kirin990 10T算力
  • 性能测试与压力测试

    一 性能测试指软件运行的各方面指标 百度百科定义 性能测试 是通过自动化的测试工具模拟多种正常 峰值以及异常负载条件来对系统的各项性能指标进行测试 多用户并发性能测试 负载测试 强度测试 容量测试是性能测试领域里的几个方面 其实压力测试也属
  • Ubuntu16.04 安装 Anaconda

    前言 对于我这个新手来说 安装Pandas以及其余的NumPy 和SciPy等工具包可能会有点困难 最简单的方法不是直接安装Pandas 而是安装Python和构成SciPy数据科学技术栈的最流行的工具包 IPython NumPy Mat
  • 【排错】-vSphere with Tanzu - SupervisorControlPlaneVM 卡在 NotReady 状态

    故障 最近机房意外断电 导致所有虚拟机关机 等来电之后 开启了所有虚拟机 业务均恢复正常 奇怪的是 Tanzu Workload Management Supervisor 集群 的状态为NotReady 导致部分业务pod不能正常访问 如
  • 【数据库系统概论】第十章、十一章:数据库恢复技术、并发控制

    文章目录 第十章 数据库恢复技术 事务 故障 恢复技术 恢复策略 第十一章 并发控制 并发带来的问题和解决 死锁和活锁 可串行性 封锁的粒度 第十章 数据库恢复技术 事务 事务的四大特性 ACID A 原子性 要么全做 要么全不做 C 一致
  • 100天精通Python(爬虫篇)——第45天:lxml库与Xpath提取网页数据(基础+代码实战)

    文章目录 一 爬虫提取网页数据的流程图 二 lxml库 1 下载安装 2 解析HTML网页 三 Xpath介绍 1 选取节点 2 谓语 3 选取未知节点 4 选取若干路径 5 Chrome插件 XPath Helper安装使用 6 Xpat
  • Java代码大全(持续更)

    学生管理系统 简易版本 稍后博主会发出进阶版的 希望大家喜欢 package student public class Student private String id private String name private int ag
  • C++复制构造函数和赋值符的区别

    今天做C primer的习题 被复制构造函数和赋值符的区别弄晕了 简单地说 有一道题目如下描述 class t1 class t2 t1 我先看见有一个等号 以为就是赋值符来做的 其实并不是这样的 做一个实验好了 class CTest p
  • 基于Jfinal实现的权限管理系统 JfinalUIB

    JfinalUIB 是 Jfinal charisma beetl postgresql 同时支持MySQL ehcache ztree druid bcprov 实现的用户权限管理系统 项目用到了众多的开源组件 还有一些是分享的学习代码片
  • nginx 交叉编译

    环境 Linux CentOS6 9 2 6 32 696 el6 x86 64 软件版本 nginx http nginx org download nginx 1 18 0 tar gz openssl https www openss