Can anyone please tell me how to build C-ares library in android (ndk-build)
1 Answer
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).
-
I followed your procedure from your website about building the 3rd party library. I compiled
gsl
library and it compiled successfully but when i am running the app. it is giving runtime error thatcan not locate cblas_sdsdot
. The variable is present in the lib as i checked withnm
command. Any suggestion and really sorry for invoking this 3 years old question. Jun 10, 2015 at 8:13 -
I think this deserves a dedicated StackOverflow question as you are apparently not focusing on c-ares but on gsl, right?– deltheilJun 10, 2015 at 8:53
-
here is the link to my question. I posted it today before asking here.stackoverflow.com/questions/30727709/… Jun 10, 2015 at 8:59
-
Hi, If I want to build a static library for x86, how should I replace the -march? I get an error
error: ahost-ares_getopt.o: incompatible target
when I change it into-march=i686
or-march=x86
.– wqycsuOct 30, 2017 at 13:29 -
Any idea how to do this for arm64 architecture? It doesn't appear to be as straightforward as I'd hoped.– MichaelAug 25, 2019 at 5:01