libnghttp2 NDK 交叉编译

移植nghttp2到android

创建工作目录,并进入

 
     
1
2
 
     
mkdir android
cd android

clone源码

 
     
1
 
     
git clone git@ github.com:nghttp2/nghttp2.git

生成交叉编译工具链

 
     
1
 
     
$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --arch=arm --install-dir=./toolchain

导出环境变量

 
     
1
2
3
4
5
6
 
     
export CURRENT_HOME=`pwd`
export TOOLCHAIN= $CURRENT_HOME/toolchain
export PATH= $TOOLCHAIN/bin:$PATH
export PKG_CONFIG_LIBDIR= $TOOLCHAIN/lib/pkgconfig
export CPPFLAGS= "-fPIE -I$TOOLCHAIN/sysroot/usr/include"
export LDFLAGS= "-fPIE -pie -I$TOOLCHAIN/sysroot/usr/lib"

编译并安装

 
     
1
2
3
4
5
6
7
8
9
 
     
cd nghttp2
autoreconf -i
./configure --enable- lib-only \
--host=arm-linux-androideabi \
--build= `dpkg-architecture -qDEB_BUILD_GNU_TYPE` \
--disable-shared \
--prefix= "$TOOLCHAIN/sysroot/usr/local"
make
make install

卸载

 
     
1
 
     
make uninstall

何大仙提供的shell脚本

 
     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
     
#!/bin/sh
if [! -d "nghttp2" ]; then
git clone git@github.com:nghttp2/nghttp2.git
else
cd nghttp2
git pull
cd ..
fi
# env
if [-d "out/nghttp2" ]; then
rm -fr "out/nghttp2"
fi
mkdir "out"
mkdir "out/nghttp2"
_compile() {
SURFIX= $1
TOOL= $2
ARCH_FLAGS= $3
ARCH_LINK= $4
ARCH= $5
if [! -d "out/nghttp2/${SURFIX}" ]; then
mkdir "out/nghttp2/${SURFIX}"
fi
if [! -d "toolchain_${SURFIX}" ]; then
$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --arch= ${ARCH} --install-dir=./toolchain_${SURFIX}
fi
export CURRENT_HOME=`pwd`
export TOOLCHAIN= $CURRENT_HOME/toolchain_${SURFIX}
export PATH= $TOOLCHAIN/bin:$PATH
export PKG_CONFIG_LIBDIR= $TOOLCHAIN/lib/pkgconfig
export ARCH_FLAGS= $ARCH_FLAGS
export ARCH_LINK= $ARCH_LINK
export CPPFLAGS= "-fPIE -I$TOOLCHAIN/sysroot/usr/include"
export LDFLAGS= "-fPIE -pie -I$TOOLCHAIN/sysroot/usr/lib"
cd nghttp2/
autoreconf -i
./configure --enable-lib-only --host= ${TOOL} --build=`dpkg-architecture -qDEB_BUILD_GNU_TYPE` --disable-shared --prefix= "$TOOLCHAIN/sysroot/usr/local"
make clean
make -j4
make install
cd ..
mv nghttp2/lib/.libs/libnghttp2.a out/nghttp2/ ${SURFIX}/
}
# arm
_compile "armeabi" "arm-linux-androideabi" "-mthumb" "" "arm"
# armv7
_compile "armeabi-v7a" "arm-linux-androideabi" "-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16" "-march=armv7-a -Wl,--fix-cortex-a8" "arm"
# arm64v8
_compile "arm64-v8a" "aarch64-linux-android" "" "" "arm64"
# x86
_compile "x86" "i686-linux-android" "-march=i686 -m32 -msse3 -mstackrealign -mfpmath=sse -mtune=intel" "" "x86"
# x86_64
_compile "x86_64" "x86_64-linux-android" "-march=x86-64 -m64 -msse4.2 -mpopcnt -mtune=intel" "" "x86_64"
# mips
_compile "mips" "mipsel-linux-android" "" "" "mips"
# mips64
_compile "mips64" "mips64el-linux-android" "" "" "mips64"
echo "done"

http://fucknmb.com/2017/05/24/libnghttp2-NDK%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
NDK交叉编译Boost是将Boost库编译成适用于Android平台的库文件,以便在Android应用中使用Boost库的功能。下面是一般的NDK交叉编译Boost的步骤: 1. 下载NDK:首先,你需要下载并安装Android NDK,可以从官方网站(https://developer.android.com/ndk/downloads)上获取最新版本的NDK。 2. 下载Boost库:接下来,你需要下载Boost库的源代码。你可以从Boost官方网站(https://www.boost.org/users/download/)上下载最新版本的Boost库。 3. 配置Boost库:解压下载的Boost源代码,并进入解压后的目录。在终端中执行以下命令来配置Boost库: ``` ./bootstrap.sh --with-libraries=<library_names> --with-toolset=<toolset_name> --prefix=<install_path> ``` 其中,`<library_names>`是你需要编译的Boost库的名称,可以根据你的需求进行选择;`<toolset_name>`是你要使用的编译工具链,例如`clang`或`gcc`;`<install_path>`是你希望安装Boost库的路径。 4. 编辑user-config.jam文件:在Boost源代码目录下,创建一个名为`user-config.jam`的文件,并添加以下内容: ``` using clang : <ndk_version> : <path_to_ndk>/toolchains/llvm/prebuilt/<host_os>/bin/clang++ ; ``` 其中,`<ndk_version>`是你下载的NDK的版本号,`<path_to_ndk>`是你安装NDK的路径,`<host_os>`是你的操作系统类型(例如`darwin-x86_64`或`linux-x86_64`)。 5. 开始编译Boost库:在终端中执行以下命令来开始编译Boost库: ``` ./b2 toolset=clang-<ndk_version> target-os=android link=static threading=multi variant=release install ``` 这将使用指定的编译工具链和选项来编译Boost库,并将编译结果安装到之前配置的安装路径中。 6. 完成编译:等待编译过程完成,然后你将在之前配置的安装路径中找到编译好的Boost库文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值