交叉编译RK3399上使用的Nginx(含RTMP功能)

编译机操作系统为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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值