(本博客已经不再更新了,更多的内容请移步到本人的个人网站《我的技术博客》)
注意:
由于博客编辑器兼容性的原因,本文中的代码空格和标点符号可能与实际情况存在差异。
所以在设置参数的时候,请手动输入;如果碰到错误,请检查configue --help和 gcc 里面的参数名字到底怎么写。
本文下半部分在本人的个人网站上,请移步《nginx交叉编译(下)》
参考:《参考文章》
关键词:
(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
(19)ngx_errno.c:In function 'ngx_strerror'
ngx_errno.c:In function 'ngx_strerror_init':
正文:
一般来说,编译 nginx 不会有太大的问题。但是因为 nginx 对交叉编译的支持不太好。所以如果想 nginx 移植到其它环境中,会出现比较多的问题。网上也能找到几篇关于 nginx 的交叉编译的文章,但是都是针对旧一点的版本。本文 编译的是 最新的 stalble 版本,nginx-1.6.2
1、环境设置、声明变量、执行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
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"
二、遇到的问题
(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”注释掉(令测试程序不会报错)。
三、遇到的问题
(1)问题内容:
autotest : 4 : not found
autotest:Syntax error: Unterminated quoted string bytes
./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
四、遇到的问题
(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 的问题也消失了。
五、遇到的问题:
(1)问题内容:sha1 library is not found
(2)原因分析:弄不清楚
(3)解决办法:configure的时候增加参数 --with-http_ssl_module
六、遇到的问题:
(1)问题内容:./configure : error :SSL modules require the OpenSSL library.
(2)原因分析:没有说清楚openssl的源代码路径
(3)解决办法:指明openssl代码的路径。--with-openssl=DIR(DIR表示openssl源代码解压的路径)
七、遇到的问题:
(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
剩下的内容请移步到《nginx交叉编译(下)》
欢迎关注我的个人网站《程序员网》
->https://www.itmangoto.cn/
- 有兴趣的请点击《与IT技术相关的微信公众号》