Android NDK R8E缺少stdlib.h

时间:2013-06-18 03:03:07

标签: android android-ndk java-native-interface

我正在使用Android NDK(android-ndk-r8e)测试一些本机库代码。本机库是从其makefile而不是Android的修改后的构建系统构建的。使用makefile而不是Android的构建系统是项目要求(OpenSSL和FIPS)。

需要为API 14(Android 4.0),API 16(Android 4.1)和API 17(Android 4.2)构建库。虽然它使用了库的makefile,但我们使用的是android-ndk-r8e-linux-x86_64(arm-linux-androideabi-4.7和朋友)的预构建工具链。

3个API中有2个缺少stdlib.h。例如,下面是为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

根据Auselen和Chris的反馈,我尝试为API 17构建工具链。它失败了:

$ $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

如何处理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

1 个答案:

答案 0 :(得分:4)

您应该从NDK创建standalone toolchain,并使用该版本来构建您的本机库。 您可能需要在命令行或Makefile内修改环境变量,如CCLD,以指向此新工具链的gcc。类似的东西:

CC="arm-linux-androideabi-gcc --sysroot=$SYS_ROOT"
LD="arm-linux-androideabi-ld"