下载所需源码包并解压
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
wget http://www.openssl.org/source/old/1.0.0/openssl-1.0.0e.tar.gz
wget http://mirrors.sohu.com/nginx/nginx-1.8.0.tar.gz
tar xvf nginx-1.8.0.tar.gz
tar xvf openssl-1.0.0e.tar.gz
tar xvf pcre-8.37.tar.gz
进入工作目录
cd nginx-1.8.0
设置编译所需变量
BUILD_PATH=$PWD
INSTALL_PATH=$PWD/install
CC_PATH=/opt/OpenWrt-Toolchain-mt7620/bin/mipsel-openwrt-linux-gcc
CPP_PATH=/opt/OpenWrt-Toolchain-mt7620/bin/mipsel-openwrt-linux-g++
CONFIG_DIR=$INSTALL_PATH/config
LOG_DIR=$INSTALL_PATH/log
TEMP_DIR=$INSTALL_PATH/tmp
执行 ./configure
./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/gino/transplant/pcre-8.37 --with-openssl=/home/gino/transplant/openssl-1.0.0e --with-cc=$CC_PATH --with-cpp=$CPP_PATH --with-cc-opt="-I /opt/OpenWrt-Toolchain-mt7620/include" --with-ld-opt="-L /opt/OpenWrt-Toolchain-mt7620/lib"
执行 configure 遇见的错误
- 问题内容
原因分析checking for C compiler ... found but is not working ./configure: error: C compiler /opt/OpenWrt-Toolchain-mt7620/bin/mipsel-openwrt-linux-gcc is not found
configure首先会编译一个小测试程序,通过测试其运行结果来判断编译器是否能正常工作,由于交叉编译器所编译出的程序是无法在编译主机上运行的,故而产生此错误。
解决办法:
编辑auto/cc/name文件,将21行的“exit 1”注释掉(令测试程序不会退出)
- 问题内容
原因分析checking for int size ...objs/autotest: 1: objs/autotest: Syntax error: "(" unexpected bytes ./configure: error: can not detect int size cat: objs/autotest.c: No such file or directory
configure通过运行测试程序来获得“int、long、longlong”等数据类型的大小,由于交叉编译器所编译出的程序无法在编译主机上运行而产生错误。
解决办法:可以通过修改configure文件来手动指定各数据类型的大小,但会非常麻烦。这里,由于编译主机与目标平台均为32位系统,故可以用“gcc”替代“mips-openwrt-linux-gcc”来进行数据类型大小的测试(注意:不同的编译环境可能编译器有点不同)
编辑auto/types/sizeof文件,大概36行的位置( $CC 改为 gcc )
- 问题内容
原因分析:检测不到size./configure: error: can not detect int size cat: objs/autotest.c: No such file or directory
解决办法:两个问题,一个是检测不到size。一个是找不到测试程序源代码。
先解决 size 问题,修改 auto/types/sizeof 文件,找到 ngx_size= 这一行,改为 ngx_size=4
修改完之后,再次configure,发现 autotest.c 的问题也消失了。
执行 make 遇见的错误
- 问题内容
原因分析: 执行 pcre 的 .configure 时参数出错。checking whether we are cross compiling... configure: error: in `/home/gino/transplant/pcre-8.37': configure: error: cannot run C compiled programs. If you meant to cross compile, use `--host'. See `config.log' for more details
解决办法:修改 objs/Makefile
将
改为/home/gino/transplant/pcre-8.37/Makefile: objs/Makefile cd /home/gino/transplant/pcre-8.37 \ && if [ -f Makefile ]; then $(MAKE) distclean; fi \ && CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \ ./configure --disable-shared
/home/gino/transplant/pcre-8.37/Makefile: objs/Makefile cd /home/gino/transplant/pcre-8.37 \ && if [ -f Makefile ]; then $(MAKE) distclean; fi \ && CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \ ./configure --disable-shared --prefix=/home/gino/transplant/pcre-8.37/tmp --host=mipsel-openwrt-linux --build=i686-linux
- 执行 make 时发现 openssl 使用的编译器是 gcc,原因是 make 的时候执行 config 生成 openssl 的 Makefile 中的 CC 是 gcc。解决办法是修改 openssl 的 Makefile 。(修改完之后make依旧会重新生成 openssl 的 Makefile,所以需要将 objs/Makefile 中关于生成 openssl 中 Makefile 的 config 注释掉。后续还会出现汇编文件报错,要在 config 的参数中加上 no-asm 然后执行 make 生成 openssl Makefile,然后修改 openssl Makefile 的 CC 变量)
- 问题内容
原因分析: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);
NGX_SYS_NERR未定义,NGX_SYS_NERR正常情况下应定义在objs/ngx_auto_config.h文件中,特别注意,这是一个auto性质的文件,只有在执行了./configure后,才能生成这个文件。宏NGX_SYS_NERR的意义为,在Linux系统中有132个错误编码。
解决办法:
找到ngx_auto_config.h这个文件
在文件中添加如下三行:#ifndef NGX_SYS_NERR #define NGX_SYS_NERR 132 #endif
- 问题内容
原因分析:`ngx_shm_free'函数未定义/home/gino/transplant/nginx-1.8.0/src/core/ngx_cycle.c:457: undefined reference to `ngx_shm_free' /home/gino/transplant/nginx-1.8.0/src/core/ngx_cycle.c:462: undefined reference to `ngx_shm_alloc' /home/gino/transplant/nginx-1.8.0/src/core/ngx_cycle.c:648: undefined reference to `ngx_shm_free' objs/src/event/ngx_event.o: In function `ngx_event_module_init': /home/gino/transplant/nginx-1.8.0/src/event/ngx_event.c:513: undefined reference to `ngx_shm_alloc' collect2: error: ld returned 1 exit status
通过查看源码可以发现,`ngx_shm_free'定义在
src/os/unix/ngx_shmem.c文件中,这个函数要正常使用的话必须要求
“NGX_HAVE_MAP_ANON、NGX_HAVE_MAP_DEVZERO、NGX_HAVE_SYSVSHM”这三个宏中有一个被定义。
解决办法:
修改ngx_auto_config.h ,加入这几行:#ifndef NGX_HAVE_SYSVSHM #define NGX_HAVE_SYSVSHM 1 #endif