linux 交叉编译 nginx,nginx 交叉编译 ( 上 )

(本博客已经再也不更新了,更多的内容请移步到本人的我的网站《个人技术博客》)html

注意:linux

因为博客编辑器兼容性的缘由,本文中的代码空格和标点符号可能与实际状况存在差别。nginx

因此在设置参数的时候,请手动输入;若是碰到错误,请检查configue --help和 gcc 里面的参数名字到底怎么写。程序员

本文下半部分在本人的我的网站上,请移步《nginx交叉编译(下)》ubuntu

关键词:app

(1)nginx 、 nginx-1.6.2

(3)mips、openwrt

(2)cross compile 、交叉编译

(5)openssl 、 pcre 、zlib

(8)sha1 library is not found

(9)SSL modules require the OpenSSL library.

(10)make没有什么能够作的为 `default'。

(11)没有规则能够建立 nginx.o须要的目标 nginx.h

(12)checking for C compiler ... found but is not working

(13)autotest not found

(14)ELF ld-uClibc.so.0not found

(15)can not detect int size

(16)autotest.c: No such file or directory

(17)没有规则能够建立nginx.o须要的目标nginx.h

(18)If you meant to cross compile, use `--host'.

See config.log for more details

(19)ngx_errno.c:In function 'ngx_strerror'编辑器

ngx_errno.c:In function 'ngx_strerror_init':测试

(20)error: 'NGX_SYS_NERR' undeclared (first use in this function)

(21)Relocations in generic ELF (EM: 3)

(22)libssl.a:could not read symbols: File in wrong format

(23)x86cpuid.s

正文:网站

通常来讲,编译 nginx 不会有太大的问题。可是由于 nginx 对交叉编译的支持不太好。因此若是想 nginx 移植到其它环境中,会出现比较多的问题。网上也能找到几篇关于 nginx 的交叉编译的文章,可是都是针对旧一点的版本。本文 编译的是 最新的 stalble 版本,nginx-1.6.2

一、环境设置、声明变量、执行configure

(1)openwrt 环境变量

STAGING_DIR=/home/ubuntu/workplace/sdk/toolchain:$STAGING_DIR

export STAGING_DIR;

(2)export PATH=$PATH:/home/ubuntu/workplace/sdk/toolchain/bin

(3)nginx 编译用到的变量

BUILD_PATH=$PWD

INSTALL_PATH=$PWD/install

CC_PATH=/home/ubuntu/workplace/sdk/toolchain/bin/mips-openwrt-linux-uclibc-gcc

CPP_PATH=/home/ubuntu/workplace/sdk/toolchain/bin/mips-openwrt-linux-uclibc-g++

CONFIG_DIR=/app/nginx

LOG_DIR=/app/nginx/log

TEMP_DIR=/app/nginx/tmp

(4)执行configure,生成Makefile(因为博客编辑器的问题,下面的标点符号可能有误,直接复制粘贴会出报错)

./configure \

--prefix=$INSTALL_PATH\

--builddir=$BUILD_PATH/build \

--conf-path=$CONFIG_DIR/nginx.conf \

--error-log-path=$LOG_DIR/error.log \

--pid-path=$CONFIG_DIR/nginx.pid \

--lock-path=$CONFIG_DIR/nginx.lock \

--http-log-path=$LOG_DIR/access.log \

--http-client-body-temp-path=$TEMP_DIR/body \

--http-proxy-temp-path=$TEMP_DIR/proxy \

--http-fastcgi-temp-path=$TEMP_DIR/fastcgi \

--without-http_uwsgi_module \

--without-http_scgi_module \

--without-http_gzip_module \

--with-http_ssl_module \

--with-pcre=/home/ubuntu/packets/pcre-6.7 \

--with-openssl=/home/ubuntu/packets/openssl-1.0.1i \

--with-cc=$CC_PATH  \

--with-cpp=$CPP_PATH \

--with-cc-opt="-I /home/ubuntu/workplace/sdk/toolchain/include" \

--with-ld-opt="-L /home/ubuntu/workplace/sdk/toolchain/lib"

(4)执行make 和make install

2、遇到的问题

(1)问题内容:

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

./configure error : C compiler gcc is not found

(2)缘由分析:

configure首先会编译一个小测试程序,经过测试其运行结果来判断编译器是否能正常工做,因为交叉编译器所编译出的程序是没法在编译主机上运行的,故而产生此错误。

(3)解决办法:

编辑auto/cc/name文件,将21行的“exit 1”注释掉(令测试程序不会报错)。

3、遇到的问题

(1)问题内容:

autotest : 4 : not found

autotest:Syntax error: Unterminated quoted stringbytes

./configure : error:can not detect int size

cat : /home/ubuntu/packets/nginx-1.6.2/build/autotest.c: No such file or directory

(2)缘由分析:

configure经过运行测试程序来得到“int、long、longlong”等数据类型的大小,因为交叉编译器所编译出的程序没法在编译主机上运行而产生错误。

(3)解决办法:能够经过修改configure文件来手动指定各数据类型的大小,但会很是麻烦。这里,因为编译主机与目标平台均为32位系统,故能够用“gcc”替代“mips-openwrt-linux-gcc”来进行数据类型大小的测试(注意:不一样的编译环境可能编译器有点不一样)

编辑auto/types/sizeof文件,大概36行的位置( $CC 改成 gcc )

ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS

该为ngx_test="gcc$CC_TEST_FLAGS $CC_AUX_FLAGS

4、遇到的问题

(1)问题内容:

./configure:error:can not detect int size

cat:/home/ubuntu/packets/nginx-1.6.2/build/autotest.c: No such file ordirectory

(2)缘由分析:检测不到size

(3)解决办法:两个问题,一个是检测不到size。一个是找不到测试程序源代码。

先解决 size问题,修改 auto/types/sizeof文件,找到 ngx_size=这一行,改成 ngx_size=4

修改完以后,再次configure,发现 autotest.c的问题也消失了。

5、遇到的问题:

(1)问题内容:sha1 library is not found

(2)缘由分析:弄不清楚

(3)解决办法:configure的时候增长参数 --with-http_ssl_module

6、遇到的问题:

(1)问题内容:./configure : error :SSL modules require the OpenSSL library.

(2)缘由分析:没有说清楚openssl的源代码路径

(3)解决办法:指明openssl代码的路径。--with-openssl=DIR(DIR表示openssl源代码解压的路径)

7、遇到的问题:

(1)问题内容:make:没有什么能够作的为`default'。

(2)缘由分析:没有说清楚openssl的源代码路径

(3)解决办法:

进入build目录(具体是哪一个目录,须要察看Makefile,执行make)

譬如说个人 configure 生成的 Makefile里面有一段

build:

$(MAKE) -f /home/ubuntu/packets/nginx-1.6.2/build/Makefile

$(MAKE) -f /home/ubuntu/packets/nginx-1.6.2/build/Makefile manpage

因此应该进入/home/ubuntu/packets/nginx-1.6.2/build目录,执行make

IT从业人员须要及时关注技术动态,可是互联网的内容却过于离散,好东西每每隐藏得很深。如今能够在微信公众号里面

搜索关注“小鱼儿的IT技术分享”,订阅我为你们天天汇总的IT技术信息。欢迎你们关注!

6cd6c556410c4ffb9eba49b2.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值