(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) 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/arm-linux-androideabi-g++" \
CXXCPP="CPATH/arm-linux-androideabi-gcc" \
AR="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="-LNDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin"
CPP="CPATH/arm-linux-androideabi-g++"
CXXCPP="CPATH/arm-linux-androideabi-gcc"
LD="CPATH/arm-linux-androideabi-ar"
AS="CC CPP=AR AS=CXX CXXCPP=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="CC_TEST_FLAGS CC_TEST_FLAGS PCRE_CONF_OPT
修改为
./configure --disable-shared OPENSSL/.openssl/include/openssl/ssl.h: OPENSSL \\
&& if [ -f Makefile ]; then $(MAKE) clean; fi \\
&& ./config --prefix=OPENSSL_OPT \\
&& $(MAKE) \\
&& $(MAKE) install LIBDIR=lib
修改为
NGX_MAKEFILE
cd BUILD_PATH \
--builddir=CC_PATH \
--with-cpp=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
大工告成
---------------------------
libdirs -o link_objects link_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);
---------------------------
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) 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/arm-linux-androideabi-g++" \
CXXCPP="CPATH/arm-linux-androideabi-gcc" \
AR="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="-LNDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin"
CPP="CPATH/arm-linux-androideabi-g++"
CXXCPP="CPATH/arm-linux-androideabi-gcc"
LD="CPATH/arm-linux-androideabi-ar"
AS="CC CPP=AR AS=CXX CXXCPP=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="CC_TEST_FLAGS CC_TEST_FLAGS PCRE_CONF_OPT
修改为
./configure --disable-shared OPENSSL/.openssl/include/openssl/ssl.h: OPENSSL \\
&& if [ -f Makefile ]; then $(MAKE) clean; fi \\
&& ./config --prefix=OPENSSL_OPT \\
&& $(MAKE) \\
&& $(MAKE) install LIBDIR=lib
修改为
NGX_MAKEFILE
cd BUILD_PATH \
--builddir=CC_PATH \
--with-cpp=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
大工告成
---------------------------
libdirs -o link_objects link_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);
---------------------------
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于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最大的设计失误
· 单元测试从入门到精通