(Not OK) 在CentOS7—编译nginx—for—Android

HOST: centos 7

NGINX VERSION: nginx-1.9.7

ZLIB VERSION: zlib-1.2.8

PCRE VERSION: pcre-8.37

[root@localhost nginx-on-android]# pwd
/opt/cBPM-android/nginx-on-android
[root@localhost nginx-on-android]# ls
nginx-1.9.7  nginx_mod_h264_streaming-2.2.7  nginx-rtmp-module  openssl-1.0.1p  pcre-8.37  zlib-1.2.8

++++++++++++++++++++++++++++++++++++++++

参考:http://m.blog.csdn.net/blog/zangcf/22688873
前面做过很多次尝试,编译也通过了,但是去掉了很多glob和crypto的函数,导致运行的时候还是会出错,所以,本次按照正常方法,加全所有的函数,然后编译之后运行。

1)在工作目录下建立build目录
/opt/cBPM-android/nginx-on-android/build

2)准备文件,

a) 下载openssl,wget wget http://www.openssl.org/source/openssl-1.0.1p.tar.gz
b) 下载nginx,wget http://nginx.org/download/nginx-1.9.7.tar.gz
c) 下载pcre,wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
d) 下载zlib,wget http://www.zlib.net/zlib-1.2.8.tar.gz
e) 下载下载nginx_mod_h264,wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
f) 下载rtmp模组,git clone https://github.com/arut/nginx-rtmp-module


3) 编译openssl
a) tar tar xvf openssl-1.0.1p.tar.gz
b) cd openssl-1.0.1p

c) 使用如下的配置文件
--------------------------------my_configure_openssl.sh start here-----------------------------------------
#!/bin/sh
./config no-asm shared \
--prefix=/opt/cBPM-android/nginx-on-android/build \
--------------------------------my_configure_openssl.sh end here-----------------------------------------

d) gedit Makefile,进入修改Makefile
    1 step) 找到所有的-m64,删除
    2 step) 找到CC= gcc,替换为CC= /opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
    3 step) 找到AR= ar (ARFLAGS)rAR=/opt/androidonlinux/androidndkr8e/toolchains/armlinuxandroideabi4.7/prebuilt/linuxx8664/bin/armlinuxandroideabiar(ARFLAGS) r
    4 step) 找到RANLIB= /usr/bin/ranlib,替换为RANLIB= /opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib
    5 step) 找到NM= nm,修改为NM= /opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc-nm
    6 step) 找到MAKEDEPPROG= gcc,修改为MAKEDEPPROG= /opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc

e)cp Makefile Makefile.ok
f)执行make -j4 && make install



+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
或者 使用下面方法:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
参考: https://wiki.openssl.org/index.php/Android

下载makedepend.zip , 从http://llg.cubic.org/docs/vc7.html下载。 解压编译,然后 cp makedepend /bin/
下载Setenv-android.sh , wget https://wiki.openssl.org/images/7/70/Setenv-android.sh

[root@localhost openssl-1.0.1p]# gedit Setenv-android.sh        //关键设置如下:
#-------------------------------------------------------
ANDROID_NDK_ROOT="/opt/android-on-linux/android-ndk-r8e"
_ANDROID_NDK="android-ndk-r8e"
_ANDROID_EABI="arm-linux-androideabi-4.7"
_ANDROID_API="android-14"

export MACHINE=armv7
export RELEASE=2.6.37
export SYSTEM=android
export ARCH=arm
#export CROSS_COMPILE="arm-linux-androideabi-"
export CROSS_COMPILE=""
#-------------------------------------------------------

[root@localhost openssl-1.0.1p]# pwd
/opt/cBPM-android/nginx-on-android/openssl-1.0.1p

chmod a+x Setenv-android.sh
perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine --openssldir=/usr/local/ssl/android-14/
make depend
make all

find . -name "*.a"
find . -name libcrypto.a
find . -name libssl.a

readelf -h ./libcrypto.a | grep -i 'class\|machine' | head -2

cp libssl.a libcrypto.a /opt/cBPM-android/criteria-lin/lib
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


4) 编译pcre
a)tar xvf pcre-8.37.tar.gz
b) cd pcre-8.37

c) gedit my_configure_pcre.sh
-------------------------my_configure_pcre.sh start here--------------------------
#!/bin/sh
NDK_ROOT="/opt/android-on-linux/android-ndk-r8e"
CPATH="/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin"

./configure \
--host=arm-linux \
--prefix=/opt/cBPM-android/nginx-on-android/build \
CPP="CPATH/armlinuxandroideabicpp" CXX="CPATH/arm-linux-androideabi-g++" \
CXXCPP="CPATH/armlinuxandroideabicpp" CC="CPATH/arm-linux-androideabi-gcc" \
AR="CPATH/armlinuxandroideabiar" AS="CPATH/arm-linux-androideabi-as"
-------------------------my_configure_pcre.sh end here-------------------------

d) chmod +x my_configure_pcre.sh
e)./my_configure_pcre.sh
f) make -j4 && make install

[root@localhost pcre-8.37]# find . -name "*.a"

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
或者 使用(参考)下面方法:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/bin/sh
NDK_ROOT="/opt/android-on-linux/android-ndk-r8e"
LDFLAGS="-LNDKROOT/sources/cxxstl/stlport/libs/armeabiv7aL/opt/cBPMandroid/criterialin/libL/opt/cBPMandroid/lighttpd1.4.37/src/.libslstlportstaticlgcclc"CPATH="NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin"
CPP="CPATH/armlinuxandroideabicpp"CXX="CPATH/arm-linux-androideabi-g++"
CXXCPP="CPATH/armlinuxandroideabicpp"CC="CPATH/arm-linux-androideabi-gcc"
LD="CPATH/armlinuxandroideabild"AR="CPATH/arm-linux-androideabi-ar"
AS="CPATH/armlinuxandroideabias"./configurehost=armlinuxprefix=/opt/cBPMandroid/nginxonandroid/buildCC=CC CPP=CPPAR=AR AS=ASCXX=CXX CXXCPP=CXXCPP  d) chmod u+x my_configure_pcre.sh e) ./my_configure_pcre.sh f) make && make install ++++++++++++++++ 编译pcre,也可以参考:http://blog.chinaunix.net/uid-14735472-id-5214130.html +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  5) 解压zlib /opt/cBPM-android/nginx-on-android/zlib-1.2.8   6) 解压nginx_mod_h264 /opt/cBPM-android/nginx-on-android/nginx_mod_h264_streaming-2.2.7  7) 编译nginx  a) tar xvf nginx-1.9.7.tar.gz b) cd nginx-1.9.7 c) gedit auto/cc/name     if [ "NGX_PLATFORM" != win32 ]; then

    ngx_feature="C compiler"
    ngx_feature_name=
    #ngx_feature_run=yes
    ngx_feature_run=no   ==>set to no to skip check
    ngx_feature_incs=
    ngx_feature_path=

        #exit 1

d) gedit auto/types/sizeof
    ngx_test="CCCC_TEST_FLAGS CCAUXFLAGS==>ngxtest="gccCC_TEST_FLAGS CC_AUX_FLAGS  e) gedit src/os/unix/ngx_errno.h     at line 15 add #define NGX_SYS_NERR 333  f) gedit src/os/unix/ngx_shmem.c     #if (NGX_HAVE_MAP_ANON) ==> #if (!NGX_HAVE_MAP_ANON)  g) gedit auto/lib/pcre/make     ./configure --disable-sharedPCRE_CONF_OPT
修改为
    ./configure --disable-shared PCRECONFOPT host=armlinux prefix=/opt/cBPMandroid/nginxonandroid/build CC=/opt/androidonlinux/androidndkr8e/toolchains/armlinuxandroideabi4.7/prebuilt/linuxx8664/bin/armlinuxandroideabigcc CPP=/opt/androidonlinux/androidndkr8e/toolchains/armlinuxandroideabi4.7/prebuilt/linuxx8664/bin/armlinuxandroideabicpp AR=/opt/androidonlinux/androidndkr8e/toolchains/armlinuxandroideabi4.7/prebuilt/linuxx8664/bin/armlinuxandroideabiar AS=/opt/androidonlinux/androidndkr8e/toolchains/armlinuxandroideabi4.7/prebuilt/linuxx8664/bin/armlinuxandroideabias CXX=/opt/androidonlinux/androidndkr8e/toolchains/armlinuxandroideabi4.7/prebuilt/linuxx8664/bin/armlinuxandroideabig++ CXXCPP=/opt/androidonlinux/androidndkr8e/toolchains/armlinuxandroideabi4.7/prebuilt/linuxx8664/bin/armlinuxandroideabicpph)geditauto/lib/openssl/makeOPENSSL/.openssl/include/openssl/ssl.h:    NGXMAKEFILEcdOPENSSL \\
    && if [ -f Makefile ]; then $(MAKE) clean; fi \\
    && ./config --prefix=ngxprefixnosharedOPENSSL_OPT \\
    && $(MAKE) \\
    && $(MAKE) install LIBDIR=lib
修改为
OPENSSL/.openssl/include/openssl/ssl.h:NGX_MAKEFILE
    cd OPENSSL \\  i) 打开/opt/cBPM-android/nginx-on-android/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c,删除  if (r->zero_in_uri)   {     return NGX_DECLINED;    }   j) gedit my_configure_nginx.sh ------------------------my_configure_nginx.sh start here------------------------ #!/bin/sh BUILD_PATH=/opt/cBPM-android/nginx-on-android/build CC_PATH=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc CPP_PATH=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ LD_PATH=/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld  ./configure \   --prefix=BUILD_PATH \
  --builddir=BUILDPATH withzlib=/opt/cBPMandroid/nginxonandroid/zlib1.2.8 withpcre=/opt/cBPMandroid/nginxonandroid/pcre8.37 withpcrejit withcc=CC_PATH  \
  --with-cpp=CPPPATH withldopt=LD_PATH  \
  --with-openssl=/opt/cBPM-android/nginx-on-android/openssl-1.0.1p \
  --add-module=/opt/cBPM-android/nginx-on-android/nginx_mod_h264_streaming-2.2.7 \
  --with-http_flv_module \
  --with-http_mp4_module \
  --add-module=/opt/cBPM-android/nginx-on-android/nginx-rtmp-module
------------------------my_configure_nginx.sh end here------------------------

[root@localhost nginx-1.9.7]# ./my_configure_nginx.sh

k) gedit ../build/Makefile
注意这里使用的arm_linux_gcc版本必须是4.4.3以后的,之前的本本可能会出错。
   1 step)找到 /opt/cBPM-android/nginx-on-android/openssl-1.0.1p/.openssl/include/openssl/ssl.h \,替换为/opt/cBPM-android/nginx-on-android/build/include/openssl/ssl.h

   2 step)找到-I /opt/cBPM-android/nginx-on-android/openssl-1.0.1p/.openssl/include \,替换为-I /opt/cBPM-android/nginx-on-android/build/include/openssl \

   3 step) CFLAGS增加-I/opt/cBPM-android/nginx-on-android/build/include

-I/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/usr/include和

   4 step) CLAGS去掉 -Werror

   5 step) 找到    /opt/cBPM-android/nginx-on-android/pcre-8.37/.libs/libpcre.a
                /opt/cBPM-android/nginx-on-android/openssl-1.0.1p/.openssl/lib/libssl.a,
                /opt/cBPM-android/nginx-on-android/openssl-1.0.1p/.openssl/lib/libcrypto.a
                /opt/cBPM-android/nginx-on-android/pcre-8.37/.libs/libpcre.a
            替换为/opt/cBPM-android/nginx-on-android/build/lib/*.a  (上面四个文件的路径,位于同一个文件夹)

   6 step) 在链接目标文件增加libc的标准库地址/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/usr/lib/libcrypt.a和/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/usr/lib/libc.a /opt/cBPM-android/nginx-on-android/build/lib/libpcre.a



这里如果集成Makefile还有找不到的文件,需要指定链接过程,类似做法如上。

l) make -j4 && make install

大工告成   

---------------------------
linkerlibdirs -o exeoutput/opt/androidonlinux/androidndkr8e/platforms/android14/archarm/usr/lib/crtbeginstatic.olink_objects linkresobjectslink_options $libs /opt/android-on-linux/android-ndk-r8e/platforms/android-14/arch-arm/usr/lib/crtend_android.o

---------------------------
错误:
src/os/unix/ngx_linux_config.h:32:18: fatal error: glob.h: No such file or directory
解决:
参考:https://groups.google.com/forum/#!topic/Android-ndk/vSH6MWPD0Vk

[root@localhost nginx-1.9.7]# wget https://github.com/white-gecko/TokyoCabinet/raw/master/glob.h
[root@localhost nginx-1.9.7]# wget https://github.com/white-gecko/TokyoCabinet/raw/master/glob.c
[root@localhost nginx-1.9.7]# cp glob.* /opt/cBPM-android/nginx-on-android/build/

---------------------------
[root@localhost nginx-1.9.7]# gedit src/core/ngx_rwlock.c
#error ngx_atomic_cmp_set() is not defined!
改为:
//#error ngx_atomic_cmp_set() is not defined!
---------------------------
[root@localhost nginx-1.9.7]# gedit /opt/cBPM-android/nginx-on-android/zlib-1.2.8/contrib/minizip/crypt.h
添加:
#include "zconf.h"
---------------------------
[root@localhost nginx-1.9.7]# gedit src/core/ngx_config.h
添加
#include <ngx_posix_config.h>
---------------------------
/opt/cBPM-android/nginx-on-android/nginx-rtmp-module/ngx_rtmp_exec_module.c:774:23: error: 'PR_SET_PDEATHSIG' undeclared (first use in this function)

[root@localhost nginx-1.9.7]# gedit /opt/cBPM-android/nginx-on-android/nginx-rtmp-module/ngx_rtmp_exec_module.c

                prctl(PR_SET_PDEATHSIG, e->kill_signal, 0, 0, 0);
改为:
                //prctl(PR_SET_PDEATHSIG, e->kill_signal, 0, 0, 0);
---------------------------


posted @   张同光  阅读(200)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示