编译机操作系统为Ubuntu 19.04。交叉编译需要用到的软件包为
openssl-1.1.1g
pcre-8.44.tar.gz
zlib-1.2.11.tar.gz
nginx-1.18.0.tar.gz
RTMP功能由pingos提供 https://github.com/pingostack/pingos
一、
先安装git然后使用git把pingos代码拉下来
git clone https://github.com/pingostack/pingos.git
二、
进入pingos/modules目录
把其他软件包上传进来。并全部解压。
三、
cd nginx-1.18.0目录
./configure --user=root --group=root \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/logs/nginx.pid \
--error-log-path=/usr/local/nginx/logs/error.log \
--with-http_ssl_module \
--with-cc=aarch64-linux-gnu-gcc \
--with-cpp=aarch64-linux-gnu-cpp \
--with-pcre=../pcre-8.44 \
--with-openssl=../openssl-1.1.1g \
--add-module=../nginx-client-module \
--add-module=../nginx-multiport-module \
--add-module=../nginx-toolkit-module \
--add-module=../nginx-rtmp-module \
--with-http_flv_module \
--with-http_mp4_module \
--with-debug \
--without-http_upstream_zone_module \
--with-zlib=../zlib-1.2.11 \
--with-http_stub_status_module \
--with-cc-opt='-D_FILE_OFFSET_BITS=64 -D_LARGE_FILE' \
--with-ld-opt='-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE'
配置命令如上。
四、configure时的一些错误:
1.
checking for C compiler ... found but is not working
./configure: error: C compiler aarch64-linux-gnu-gcc is not found
解决办法:
vim auto/cc/name
#编辑这个文件
ngx_feature="C compiler"
ngx_feature_name=
ngx_feature_run=yes
==》ngx_feature_run=no
ngx_feature_incs=
2.
checking for accept4() ... found
checking for eventfd() ... found
checking for int size ..../configure: 1: auto/types/sizeof: objs/autotest: Exec format error
bytes
./configure: error: can not detect int size
解决办法:
vim auto/types/sizeof
#编辑这个文件
if [ -x $NGX_AUTOTEST ]; then
ngx_size=`$NGX_AUTOTEST`
echo " $ngx_size bytes"
fi
#修改为
if [ -x $NGX_AUTOTEST ]; then
ngx_size=8
echo " $ngx_size bytes"
fi
#因为autotest测试程序在3399板子上跑的大部分结果就是8
但是得加点内容,给特定的类型定义为4
if [ -x $NGX_AUTOTEST ]; then
ngx_size=8
if [ "${ngx_type}" = "int" ];then
ngx_size=4
fi
if [ "${ngx_type}" = "sig_atomic_t" ];then
ngx_size=4
fi
echo " $ngx_size bytes"
fi
3.checking epoll not found
解决办法:
vim auto/os/linux
#编辑这个文件
ngx_feature_name="NGX_HAVE_EPOLL"
ngx_feature_run=yes
#改为
ngx_feature_name="NGX_HAVE_EPOLL"
ngx_feature_run=no
五、make时的一些错误:
1.pcre编译失败
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/wjk/pingos/modules/pcre-8.44':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
make[1]: *** [objs/Makefile:1872: ../pcre-8.44/Makefile] Error 1
解决办法:
cd ../pcre-8.44
./configure --host=aarch64-linux-gnu
make -j4
编译完再回到nginx继续编译
2.
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);
^~~~~~~~~~~~
make[1]: *** [objs/Makefile:835: objs/src/os/unix/ngx_errno.o] Error 1
make[1]: *** Waiting for unfinished jobs....
解决办法:
vim objs/ngx_auto_config.h
修改这个文件,在末尾加上下面这三行,包含前面的#号
#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR 135
#endif
3.编译openssl时出现错误
/wjk/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/6.3.1/../../../../aarch64-linux-gnu/bin/ld: ../openssl-1.1.1g/.openssl/lib/libssl.a(methods.o): Relocations in generic ELF (EM: 62)
../openssl-1.1.1g/.openssl/lib/libssl.a: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
make[1]: *** [objs/Makefile:325: objs/nginx] Error 1
解决办法:
vim auto/lib/openssl/make
#编辑这个文件
$OPENSSL/.openssl/include/openssl/ssl.h: $NGX_MAKEFILE
cd $OPENSSL \\
&& if [ -f Makefile ]; then \$(MAKE) clean; fi \\
&& ./config --prefix=$ngx_prefix no-shared no-threads $OPENSSL_OPT \\
&& \$(MAKE) \\
&& \$(MAKE) install_sw LIBDIR=lib
改./config这行
$OPENSSL/.openssl/include/openssl/ssl.h: $NGX_MAKEFILE
cd $OPENSSL \\
&& if [ -f Makefile ]; then \$(MAKE) clean; fi \\
&& ./Configure --prefix=$ngx_prefix no-shared no-threads --cross-compile-prefix=aarch64-linux-gnu- linux-generic64 \\
&& \$(MAKE) \\
&& \$(MAKE) install_sw LIBDIR=lib
#注意config改成Configure
改完需要重新./configure项目,上面的一些修改可能会复原,需要重新修改。
4.
objs/src/core/ngx_cycle.o: In function `ngx_init_cycle':
/wjk/pingos/modules/nginx-1.18.0/src/core/ngx_cycle.c:476: undefined reference to `ngx_shm_alloc'
/wjk/pingos/modules/nginx-1.18.0/src/core/ngx_cycle.c:685: undefined reference to `ngx_shm_free'
/wjk/pingos/modules/nginx-1.18.0/src/core/ngx_cycle.c:902: undefined reference to `ngx_shm_free'
objs/src/event/ngx_event.o: In function `ngx_event_module_init':
/wjk/pingos/modules/nginx-1.18.0/src/event/ngx_event.c:551: undefined reference to `ngx_shm_alloc'
objs/addon/nginx-multiport-module/ngx_process_slot_module.o: In function `ngx_process_slot_module_init':
/wjk/pingos/modules/nginx-1.18.0/../nginx-multiport-module/ngx_process_slot_module.c:92: undefined reference to `ngx_shm_alloc'
objs/addon/nginx-multiport-module/ngx_stream_zone_module.o: In function `ngx_stream_zone_init_conf':
/wjk/pingos/modules/nginx-1.18.0/../nginx-multiport-module/ngx_stream_zone_module.c:185: undefined reference to `ngx_shm_alloc'
collect2: error: ld returned 1 exit status
make[1]: *** [objs/Makefile:325: objs/nginx] Error 1
make[1]: Leaving directory '/wjk/pingos/modules/nginx-1.18.0'
make: *** [Makefile:8: build] Error 2
解决办法:
vim objs/ngx_auto_config.h
末尾添加下面这三行,包含前面的#号
#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif
也可以直接 vim auto/unix 修改ngx_feature_run为no:
ngx_feature="System V shared memory"
ngx_feature_name="NGX_HAVE_SYSVSHM"
ngx_feature_run=yes
===>ngx_feature_run=no
ngx_feature_incs="#include <sys/ipc.h>