一、配置环境变量
export BUILD_PATH=$PWD
export INSTALL_PATH=/home/shark/nginx/install #指定编译后的安装目录
export CC_PATH=arm-hisiv300-linux-gcc #指定交叉编译工具目录
export CPP_PATH=arm-hisiv300-linux-g++ #指定交叉编译工具目录
export CONFIG_DIR=/home/shark/nginx/install/conf #指定编译后安装的配置文件目录
export LOG_DIR=/home/shark/nginx/install/log #指定编译后安装的日志文件目录
export TEMP_DIR=/home/shark/nginx/install/tmp#指定编译后安装的临时文件目录
二、编译配置
(1)cd nginx-1.8.0
./configure \
--prefix=$INSTALL_PATH \
--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/shark/nginx/pcre-8.37 \
--with-openssl=/home/shark/nginx/openssl-1.0.0e \
--with-cc=$CC_PATH ?\
--with-cpp=$CPP_PATH \
--with-cc-opt="-I /opt/hisi-linux/x86-arm/arm-hisiv300-linux/include"\
--with-ld-opt="-L /opt/hisi-linux/x86-arm/arm-hisiv300-linux/lib"
1、执行配置命令 碰到问题
- checking whether the C compiler works... configure: error: cannot run Ccompiled programs.
- If you meant to cross compile, use `--host'.
- See 'config.log' for more details.
解决:
打开 build 目录的 Makefile,找到 pcre 参数设定的那几行。
/home/ubuntu/packets/pcre-6.7/Makefile : /home/ubuntu/packets/nginx-1.6.2/build/Makefile
cd /home/ubuntu/packets/pcre-6.7 \
&& if [ -f Makefile ] ; then (MAKE) distclean; fi \ && CC="(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe "\
./configure --disable-shared
- 在 configure 那里再添加一个参数 --host=arm-hisiv300-linux
如:
./configure --disable-shared --host=arm-hisiv300-linux
2、执行make
POD document had syntax errors at /usr/bin/pod2man line 68.
Makefile:594: recipe for target 'install_docs' failed
make[2]: *** [install_docs] Error 1
解决:
打开文件 /usr/bin/pod2man 注释文件68行
vim /usr/bin/pod2man
# $parser->parse_from_file (@files);
3、
src/os/unix/ngx_errno.c
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);
解决:
进入objs目录
找到 ngx_auto_config.h 文件
增加宏定义
#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR 132
#endif
#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif
问题:
openssl-1.0.1i/.openssl/lib/libssl.a(s23_meth.o):Relocations in generic ELF(EM: 3)
libssl.a:could not read symbols: File in wrong format
解决:
进入objs目录
修改Makefile
原为:
/home/shark/nginx/openssl-1.0.0e/.openssl/include/openssl/ssl.h: objs/Makefile
cd /home/shark/nginx/openssl-1.0.0e \
&& if [ -f Makefile ]; then $(MAKE) clean; fi \
&& ./config --prefix=/home/shark/nginx/openssl-1.0.0e/.openssl no-shared - \
&& $(MAKE) \
&& $(MAKE) install LIBDIR=lib
第四行改为
&& ./config --prefix=/home/shark/nginx/openssl-1.0.0e/.openssl no-shared --cross-compile-prefix=arm-hisiv300-linux- linux-generic32 no-asm \
五、上面已经解决
x86cpuid.s:Assembler messages:
x86cpuid.s:168:Error: Unrecognized opcode `hlt`
原因是编译在 nginx 执行 configure 的时候,交叉编译参数没有很好的传到 openssl
解决
在添加–cross-compile-prefix 的那一行,继续添加一个参数 no-asm,禁用汇编代码。
六、make
done.
参考
https://www.itmangoto.cn/2017/11/28/nginx-cross-compile/