how to build c-ares library in android (NDK)

前端 未结 1 855
渐次进展
渐次进展 2021-02-06 05:38

Can anyone please tell me how to build C-ares library in android (ndk-build)

相关标签:
1条回答
  • 2021-02-06 05:53

    Here's how to build it as a static library for ARMv7 with the NDK standalone toolchain:

    export NDK=/tmp/android-ndk-r8b
    
    # Create the standalone toolchain
    $NDK/build/tools/make-standalone-toolchain.sh \
    --platform=android-9 \
    --install-dir=/tmp/my-android-toolchain
    
    export PATH=/tmp/my-android-toolchain/bin:$PATH
    export SYSROOT=/tmp/my-android-toolchain/sysroot
    export CC="arm-linux-androideabi-gcc --sysroot $SYSROOT"
    
    # Download the latest release
    curl -O http://c-ares.haxx.se/download/c-ares-1.9.1.tar.gz
    tar xvfz c-ares-1.9.1.tar.gz
    
    # Configure
    cd c-ares-1.9.1 && mkdir build
    ./configure --prefix=$(pwd)/build \
    --host=arm-linux-androideabi \
    --disable-shared \
    CFLAGS="-march=armv7-a"
    
    # Build and install
    make && make install
    

    That's it. The static library is deployed under build/lib/libcares.a.

    If you target other archs (e.g. armeabi, x86) repeat the configure with the proper -march value and re-build the library for each arch. Also, feel free to:

    • adapt the target platform to your needs (here Android 2.3, a.k.a API level 9),
    • use the configure options that fit your needs (e.g. you may want to build a dynamic library in addition, enable/disable some features, etc).
    0 讨论(0)
提交回复
热议问题