CURL NDK 交叉编译
生活随笔
收集整理的這篇文章主要介紹了
CURL NDK 交叉编译
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
移植curl到android,且支持https和http2.0
依賴前兩篇文章
- libnghttp2 NDK 交叉編譯
- openssl NDK 交叉編譯
創建工作目錄,并進入
| 12 | mkdir androidcd android |
下載源碼
| 12 | wget https://curl.haxx.se/download/curl-7.53.1.tar.gztar xfz url-7.53.1.tar.gz |
生成交叉編譯工具鏈
| 1 | $ANDROID_NDK/build/tools/make-standalone-toolchain.sh --arch=arm --install-dir=./toolchain |
導出環境變量(armeabi)
| 123456789101112131415161718 | export ANDROID_HOME=`pwd`export TOOLCHAIN=$ANDROID_HOME/toolchainexport PKG_CONFIG_LIBDIR=$TOOLCHAIN/lib/pkgconfigexport CROSS_SYSROOT=$TOOLCHAIN/sysrootexport PATH=$TOOLCHAIN/bin:$PATHexport TOOL=arm-linux-androideabiexport CC=$TOOLCHAIN/bin/${TOOL}-gccexport CXX=$TOOLCHAIN/bin/${TOOL}-g++export LINK=${CXX}export LD=$TOOLCHAIN/bin/${TOOL}-ldexport AR=$TOOLCHAIN/bin/${TOOL}-arexport RANLIB=$TOOLCHAIN/bin/${TOOL}-ranlibexport STRIP=$TOOLCHAIN/bin/${TOOL}-stripexport ARCH_FLAGS="-mthumb"export ARCH_LINK=export CFLAGS="${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64"export CXXFLAGS="${CFLAGS} -frtti -fexceptions"export LDFLAGS="${ARCH_LINK}" |
編譯并安裝
| 12345678910111213141516171819202122 | cd curl-7.53.1autoreconf -i./configure --prefix=$TOOLCHAIN/sysroot/usr/local \--with-sysroot=$TOOLCHAIN/sysroot \ --host=arm-linux-androideabi \ --with-ssl=$TOOLCHAIN/sysroot/usr/local \ --with-nghttp2=$TOOLCHAIN/sysroot/usr/local \ --enable-ipv6 \ --enable-static \ --enable-threaded-resolver \ --disable-dict \ --disable-gopher \ --disable-ldap --disable-ldaps \ --disable-manual \ --disable-pop3 --disable-smtp --disable-imap \ --disable-rtsp \ --disable-shared \ --disable-smb \ --disable-telnet \ --disable-verbosemake -j4make install |
卸載
| 1 | make uninstall |
configure完成后檢查輸出結果是否enable ssl, enable https, enable http2.0
| 1234567891011121314151617181920212223242526272829303132333435 | Configured to build curl/libcurl: curl version: 7.53.1 Host setup: arm-unknown-linux-androideabi Install prefix: /Users/lizhangqu/Desktop/android/toolchain/sysroot/usr/local Compiler: /Users/lizhangqu/Desktop/android/toolchain/bin/arm-linux-androideabi-gcc SSL support: enabled (OpenSSL) SSH support: no (--with-libssh2) zlib support: enabled GSS-API support: no (--with-gssapi) TLS-SRP support: enabled resolver: POSIX threaded IPv6 support: enabled Unix sockets support: enabled IDN support: no (--with-{libidn2,winidn}) Build libcurl: Shared=no, Static=yes Built-in manual: no (--enable-manual) --libcurl option: enabled (--disable-libcurl-option) Verbose errors: no SSPI support: no (--enable-sspi) ca cert bundle: no ca cert path: no ca fallback: no LDAP support: no (--enable-ldap / --with-ldap-lib / --with-lber-lib) LDAPS support: no (--enable-ldaps) RTSP support: no (--enable-rtsp) RTMP support: no (--with-librtmp) metalink support: no (--with-libmetalink) PSL support: no (libpsl not found) HTTP2 support: enabled (nghttp2) Protocols: FILE FTP FTPS HTTP HTTPS TFTP SONAME bump: yes - WARNING: this library will be built with the SONAME number bumped due to (a detected) ABI breakage. See lib/README.curl_off_t for details on this. |
armeabi-v7a
| 1234567891011121314151617181920212223 | $ANDROID_NDK/build/tools/make-standalone-toolchain.sh --arch=arm --install-dir=./toolchainexport TOOL=arm-linux-androideabiexport ARCH_FLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16"export ARCH_LINK="-march=armv7-a -Wl,--fix-cortex-a8"./configure --prefix=$TOOLCHAIN/sysroot/usr/local \--with-sysroot=$TOOLCHAIN/sysroot \ --host=arm-linux-androideabi \ --with-ssl=$TOOLCHAIN/sysroot/usr/local \ --with-nghttp2=$TOOLCHAIN/sysroot/usr/local \ --enable-ipv6 \ --enable-static \ --enable-threaded-resolver \ --disable-dict \ --disable-gopher \ --disable-ldap --disable-ldaps \ --disable-manual \ --disable-pop3 --disable-smtp --disable-imap \ --disable-rtsp \ --disable-shared \ --disable-smb \ --disable-telnet \ --disable-verbose |
x86
| 1234567891011121314151617181920212223 | $ANDROID_NDK/build/tools/make-standalone-toolchain.sh --arch=x86 --install-dir=./toolchainexport TOOL=i686-linux-androidexport ARCH_FLAGS="-march=i686 -msse3 -mstackrealign -mfpmath=sse"export ARCH_LINK=""./configure --prefix=$TOOLCHAIN/sysroot/usr/local \--with-sysroot=$TOOLCHAIN/sysroot \ --host=i686-linux-android \ --with-ssl=$TOOLCHAIN/sysroot/usr/local \ --with-nghttp2=$TOOLCHAIN/sysroot/usr/local \ --enable-ipv6 \ --enable-static \ --enable-threaded-resolver \ --disable-dict \ --disable-gopher \ --disable-ldap --disable-ldaps \ --disable-manual \ --disable-pop3 --disable-smtp --disable-imap \ --disable-rtsp \ --disable-shared \ --disable-smb \ --disable-telnet \ --disable-verbose |
何大仙提供的shell腳本
| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 | if [! -f "curl-7.53.1.tar.gz" ]; thenwget https://curl.haxx.se/download/curl-7.53.1.tar.gzfiif [! -d "curl-7.53.1" ]; then tar zxf curl-7.53.1.tar.gzfi# envif [-d "out/curl" ]; thenrm -fr "out/curl"fimkdir "out"mkdir "out/curl"_compile() {SURFIX=$1TOOL=$2ARCH_FLAGS=$3ARCH_LINK=$4ARCH=$5 if [! -d "out/curl/${SURFIX}" ]; thenmkdir "out/curl/${SURFIX}" fi if [! -d "toolchain_${SURFIX}" ]; then $ANDROID_NDK/build/tools/make-standalone-toolchain.sh --arch=${ARCH} --install-dir=./toolchain_${SURFIX} fi export ANDROID_HOME=`pwd` export TOOLCHAIN=$ANDROID_HOME/toolchain_${SURFIX} export PKG_CONFIG_LIBDIR=$TOOLCHAIN/lib/pkgconfig export CROSS_SYSROOT=$TOOLCHAIN/sysroot export PATH=$TOOLCHAIN/bin:$PATH export CC=$TOOLCHAIN/bin/${TOOL}-gcc export CXX=$TOOLCHAIN/bin/${TOOL}-g++ export LINK=${CXX} export LD=$TOOLCHAIN/bin/${TOOL}-ld export AR=$TOOLCHAIN/bin/${TOOL}-ar export RANLIB=$TOOLCHAIN/bin/${TOOL}-ranlib export STRIP=$TOOLCHAIN/bin/${TOOL}-strip export ARCH_FLAGS=$ARCH_FLAGS export ARCH_LINK=$ARCH_LINK export CFLAGS="${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64" export CXXFLAGS="${CFLAGS} -frtti -fexceptions" export LDFLAGS="${ARCH_LINK}" cd curl-7.53.1/autoreconf -i./configure --prefix=$TOOLCHAIN/sysroot/usr/local \--with-sysroot=$TOOLCHAIN/sysroot \--host=${TOOL} \--with-ssl=$TOOLCHAIN/sysroot/usr/local \--with-nghttp2=$TOOLCHAIN/sysroot/usr/local \--enable-ipv6 \--enable-static \--enable-threaded-resolver \--disable-dict \--disable-gopher \--disable-ldap --disable-ldaps \--disable-manual \--disable-pop3 --disable-smtp --disable-imap \--disable-rtsp \--disable-shared \--disable-smb \--disable-telnet \--disable-verbosemake cleanmake -j4make install cd ..mv curl-7.53.1/lib/.libs/libcurl.a out/curl/${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" |
總結
以上是生活随笔為你收集整理的CURL NDK 交叉编译的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: openssl NDK 交叉编译
- 下一篇: Android Gradle Plugi