一、设置交叉编译环境
这里使用的天嵌的交叉编译器,目录在
/opt/EmbedSky/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu
安装依赖环境
apt-get install pkg-config autoconf libtool automake python2.7-dev libpython2.7-dev
nano -w /etc/profile
export PATH=$PATH:/opt/EmbedSky/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin
source /etc/profile
二、下载对应的软件包
mkdir -p /srv/build/nginx
cd /srv/build/nginx
wget https://nginx.org/download/nginx-1.24.0.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/refs/heads/master.zip
mv master.zip nginx-rtmp-module.zip
tar xzvf nginx-1.24.0.tar.gz
unzip nginx-rtmp-module.zip
mv nginx-rtmp-module-master nginx-rtmp-module
wget https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.zip/download
mv download pcre-8.45.zip
unzip pcre-8.45.zip
wget http://www.zlib.net/current/zlib.tar.gz
tar xzvf zlib.tar.gz
wget https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1a.tar.gz
tar xzvf OpenSSL_1_1_1a.tar.gz
mv openssl-OpenSSL_1_1_1a libopenssl-1.1.1a
wget https://github.com/arut/nginx-dav-ext-module/archive/refs/tags/v3.0.0.tar.gz
mv v3.0.0.tar.gz nginx-dav-ext-module.tar.gz
tar xzvf nginx-dav-ext-module.tar.gz
wget https://download.gnome.org/sources/libxml2/2.10/libxml2-2.10.4.tar.xz
tar xvf libxml2-2.10.4.tar.xz
cd libxml2-2.10.4
./configure --host=aarch64-linux-gnu --prefix=/opt/EmbedSky/arm-linux-libxml2 CROSS_COMPILE=aarch64-linux-gnu- CC=aarch64-linux-gnu-gcc --without-python --without-zlib
make
make install
wget https://download.gnome.org/sources/libxslt/1.1/libxslt-1.1.36.tar.xz
tar xvf libxslt-1.1.36.tar.xz
cd libxslt-1.1.36
./configure --host=aarch64-linux-gnu --prefix=/opt/EmbedSky/arm-linux-libxslt CC=aarch64-linux-gnu-gcc --with-libxml-prefix=/opt/EmbedSky/arm-linux-libxml2 --without-python
make
make install
三、交叉编译
删除部分依赖
nano -w nginx-dav-ext-module-3.0.0/config
#ngx_module_libs=LIBXSLT
ngx_module_libs=-lxml2
生成编译指令
#export SYSROOT=/opt/EmbedSky/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/sysroot
export PATH=$PATH:/opt/EmbedSky/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin
cd nginx-1.24.0
C_INCLUDE_PATH=/opt/EmbedSky/arm-linux-libxml2/include/libxml2:/opt/EmbedSky/arm-linux-libxslt/include
export C_INCLUDE_PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/EmbedSky/arm-linux-libxml2/lib:/opt/EmbedSky/arm-linux-libsxlt/lib
export LD_LIBRARY_PATH
./configure \
--prefix=/etc/nginx \
--conf-path=/etc/nginx/nginx.conf \
--sbin-path=/usr/bin/nginx \
--pid-path=/run/nginx.pid \
--lock-path=/run/lock/nginx.lock \
--user=http \
--group=http \
--http-log-path=/opt/logs/nginx/access.log \
--error-log-path=stderr \
--http-client-body-temp-path=/var/lib/nginx/client-body \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--with-compat \
--with-debug \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--add-module="../nginx-dav-ext-module-3.0.0" \
--with-http_degradation_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-pcre-jit \
--add-module=../nginx-rtmp-module \
--with-cc=aarch64-linux-gnu-gcc \
--with-cpp=aarch64-linux-gnu-g++ \
--with-cc-opt="-I /opt/EmbedSky/arm-linux-libxml2/include/libxml2 -I /opt/EmbedSky/arm-linux-libxslt/include" \
--with-ld-opt="-L /opt/EmbedSky/arm-linux-libxml2/lib -L /opt/EmbedSky/arm-linux-libsxlt/lib" \
--with-pcre=../pcre-8.45 \
--with-openssl=../libopenssl-1.1.1a \
--with-zlib=../zlib-1.3.1
安装到目录/opt/nginx,然后压缩文件即可
make
export DESTDIR=/opt/nginx
make install
修复错误一
checking for OS
+ Linux 5.4.0-150-generic x86_64
checking for C compiler ... found but is not working
./configure: error: C compiler aarch64-linux-gnu-gcc is not found
nano -w auto/cc/name
if [ "$NGX_PLATFORM" != win32 ]; then
ngx_feature="C compiler"
ngx_feature_name=yes
ngx_feature_run=no
ngx_feature_incs=
ngx_feature_path=
ngx_feature_libs=
ngx_feature_test=
. auto/feature
# if [ $ngx_found = no ]; then
# echo
# echo $0: error: C compiler $CC is not found
# echo
# exit 1
# fi
fi
修复错误二
checking for int size ..../configure: 1: auto/types/sizeof: objs/autotest: Exec format error
bytes
./configure: error: can not detect int size
nano -w auto/types/sizeof
if [ -x $NGX_AUTOTEST ]; then
ngx_size=8
echo " $ngx_size bytes"
fi
修复错误三
checking whether we are cross compiling... configure: error: in `/srv/build/nginx/pcre-8.45':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
objs/Makefile:1798: recipe for target '../pcre-8.45/Makefile' failed
nano -w objs/Makefile 每次
CFLAGS = -DNGX_HAVE_GCC_ATOMIC=1 -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g
./pcre-8.45/Makefile: objs/Makefile
cd ../pcre-8.45 \
&& if [ -f Makefile ]; then $(MAKE) distclean; fi \
&& CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
./configure --disable-shared --enable-jit --host=aarch64-linux-gnu
修复错误四
../libopenssl-1.1.1a/.openssl/lib/libssl.a: 无法添加符号: 文件格式错误
nano -w auto/lib/openssl/make 每次
&& ./config --prefix=$ngx_prefix no-shared no-threads no-asm --cross-compile-prefix=/opt/EmbedSky/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- \\
修复错误五
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-m64’
nano -w ../libopenssl-1.1.1a/Makefile
CNF_CFLAGS=-m64 -Wa,--noexecstack
CNF_CXXFLAGS=-std=c++11 -m64
这个需要修复了执行
make && make install
错误六
core/ngx_cycle.c:485:对‘ngx_shm_alloc’未定义的引用
nano -w objs/ngx_auto_config.h
第十六行
#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif
错误七
nginx: [alert] shmget(384) failed (38: Function not implemented)
P.S. 勾選Kernel的System V IPC選項並且重新編譯下載