1.主机操作系统为ubuntu 18.04。交叉编译需要用到的软件包为
zlib-1.2.8.tar.bz2
上面文件可通过此下载链接下载
nginx.v1.6.2.tar.bz2
上面文件可通过此下载链接下载
2.交叉编译nginx
1)将zlib nginx包解压
tar -xvf zlib-1.2.8.tar.bz2
tar -xvf nginx.v1.6.2.tar.bz2
2)配置configure
cd nginx/nginx-1.6.2
mkdir nginx
vi b.sh
CC_PATH=/opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-gcc#交叉编译工具路径
CPP_PATH=/opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-g++#交叉编译工具路径
HOME_NGINX=/xxxx/xxxx/xxxx/xxx/ #解压出来的路径可用pwd代替
#./configure --prefix=/opt/project/hi3559a/lib_add/nginx \
./configure --prefix=./nginx \
--add-module=$HOME_NGINX/nginx/arut-nginx-rtmp-module-7a35372 \
--with-zlib=$HOME_NGINX/zlib-1.2.8 \
--without-pcre --without-http_rewrite_module \
--with-http_ssl_module \
--with-openssl=$HOME_NGINX/nginx/openssl-1.0.2 \
--with-cc=$CC_PATH \
--with-cpp=$CPP_PATH
3)交叉编译
./b.sh
make ;make install
3.遇到的坑
1)error: 'NGX_SYS_NERR’错误
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/Makefile:680: recipe for target 'objs/src/os/unix/ngx_errno.o' failed
make[1]: *** [objs/src/os/unix/ngx_errno.o] Error 1
make[1]: Leaving directory '/opt/project/hi3559a/lib_src/nginx/nginx-1.6.2'
Makefile:8: recipe for target 'build' failed
make: *** [build] Error 2
出错的原因仍然是因为交叉编译程序无法本地运行,导致NGX_SYS_NERR宏没有赋值。解决办法,手动编辑 objs/ngx_auto_config.h,加上
vi objs/ngx_auto_config.h
#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR 132
#endif
2)ngx_shm_free错误
objs/src/core/ngx_cycle.o: In function `ngx_init_cycle':
/opt/project/hi3559a/lib_src/nginx/nginx-1.6.2/src/core/ngx_cycle.c:457: undefined reference to `ngx_shm_free'
/opt/project/hi3559a/lib_src/nginx/nginx-1.6.2/src/core/ngx_cycle.c:462: undefined reference to `ngx_shm_alloc'
/opt/project/hi3559a/lib_src/nginx/nginx-1.6.2/src/core/ngx_cycle.c:648: undefined reference to `ngx_shm_free'
objs/src/event/ngx_event.o: In function `ngx_event_module_init':
/opt/project/hi3559a/lib_src/nginx/nginx-1.6.2/src/event/ngx_event.c:525: undefined reference to `ngx_shm_alloc'
collect2: error: ld returned 1 exit status
objs/Makefile:256: recipe for target 'objs/nginx' failed
make[1]: *** [objs/nginx] Error 1
make[1]: Leaving directory '/opt/project/hi3559a/lib_src/nginx/nginx-1.6.2'
Makefile:8: recipe for target 'build' failed
make: *** [build] Error 2
解决办法
vi objs/ngx_auto_config.h
#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif
4.移植到hi3559a
将当前目录下的nginx目录下所有移植到海思3559a上
修改nginx/conf/nginx.conf
vi nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
修改如下
user root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
运行
./nginx -c /opt/project/hi3559a/lib_add/nginx/conf/nginx.conf -p /opt/project/hi3559a/lib_add/nginx/
结束