Can anyone please tell me how to build C-ares library in android (ndk-build)
Asked
Active
Viewed 5,924 times
1 Answers
14
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).

deltheil
- 15,496
- 2
- 44
- 64
-
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 that `can not locate cblas_sdsdot`. The variable is present in the lib as i checked with `nm` command. Any suggestion and really sorry for invoking this 3 years old question. – Saad Saadi Jun 10 '15 at 08:13
-
I think this deserves a dedicated StackOverflow question as you are apparently not focusing on c-ares but on gsl, right? – deltheil Jun 10 '15 at 08:53
-
here is the link to my question. I posted it today before asking here.http://stackoverflow.com/questions/30727709/gsl-nm-outputs-undefined-symbol-u?noredirect=1#comment49530515_30727709 – Saad Saadi Jun 10 '15 at 08: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`. – wqycsu Oct 30 '17 at 13:29
-
Any idea how to do this for arm64 architecture? It doesn't appear to be as straightforward as I'd hoped. – Michael Aug 25 '19 at 05:01