I'm testing some native library code with the Android NDK (android-ndk-r8e). The native library is being built from its makefile rather than Android's modified build system. Using the makefile rather than Android's build system is a project requirement (OpenSSL and FIPS).
The library needs to be built for API 14 (Android 4.0), API 16 (Android 4.1), and API 17 (Android 4.2). Though its using the library's makefile, we are using the prebuilt toolchain from android-ndk-r8e-linux-x86_64 (arm-linux-androideabi-4.7 and friends).
It appears stdlib.h
is missing from 2 of the 3 APIs. For example, below is an attempt to compile for API 17.
arm-linux-androideabi-gcc -I. -I.. -I../include -DOPENSSL_FIPSCANISTER -fPIC -DOPENSSL_PIC
-DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,--noexecstack -march=armv7-a
-mandroid -I/opt/android-ndk-r8e/platforms/android-17/arch-arm/usr/include
-B/opt/android-ndk-r8e/platforms/android-17/arch-arm/usr/lib -O3 -fomit-frame-pointer -Wall
-DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DAES_ASM
-DGHASH_ASM -c -o cryptlib.o cryptlib.c
In file included from cryptlib.c:117:0:
cryptlib.h:62:20: fatal error: stdlib.h: No such file or directory
Based on feedback from Auselen and Chris, I tried to build a toolchain for API 17. It failed:
$ $ANDROID_NDK_ROOT/build/tools/make-standalone-toolchain.sh --platform=android-17 --install-dir=./android-testAuto-config: --toolchain=arm-linux-androideabi-4.6
Invalid platform name: android-17
Please use --platform=<name> with one of: android-14 android-3 android-4 android-5 android-8 android-9
How does one handle missing headers in the NDK?
$ find /opt/android-ndk-r8e/ -iname stdlib.h
/opt/android-ndk-r8e/platforms/android-5/arch-arm/usr/include/stdlib.h
/opt/android-ndk-r8e/platforms/android-14/arch-mips/usr/include/stdlib.h
/opt/android-ndk-r8e/platforms/android-14/arch-x86/usr/include/stdlib.h
/opt/android-ndk-r8e/platforms/android-14/arch-arm/usr/include/stdlib.h
/opt/android-ndk-r8e/platforms/android-9/arch-mips/usr/include/stdlib.h
/opt/android-ndk-r8e/platforms/android-9/arch-x86/usr/include/stdlib.h
/opt/android-ndk-r8e/platforms/android-9/arch-arm/usr/include/stdlib.h
/opt/android-ndk-r8e/platforms/android-8/arch-arm/usr/include/stdlib.h
/opt/android-ndk-r8e/platforms/android-4/arch-arm/usr/include/stdlib.h
/opt/android-ndk-r8e/platforms/android-3/arch-arm/usr/include/stdlib.h
/opt/android-ndk-r8e/sources/cxx-stl/stlport/stlport/stdlib.h
/opt/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/tr1/stdlib.h
/opt/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.7/include/tr1/stdlib.h
/opt/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.4.3/include/tr1/stdlib.h
You should create a standalone toolchain from NDK, and use that one to build your native library.
You will probably need to modify environment variables like CC
, LD
on the command line or inside Makefile to point to this new toolchain's gcc
. Something like:
CC="arm-linux-androideabi-gcc --sysroot=$SYS_ROOT"
LD="arm-linux-androideabi-ld"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With