Issue
Using the Android NDK I'd like to know which target architecture is active when executing pre-processor code in my C++ header files. For example, my code would behave differently on "armeabi" vs. "armv7".
The $(TARGET_ARCH) variable can be used within makefiles, but is there an equivalent that's accessible from within C++ headers?
Thanks.
Solution
In addition to what Dan Albert posted, the hello-jni
example actually already shows the necessary ifdefs for detecting the different ABIs:
https://github.com/googlesamples/android-ndk/blob/master/hello-jni/app/src/main/cpp/hello-jni.c
#if defined(__arm__)
#if defined(__ARM_ARCH_7A__)
#if defined(__ARM_NEON__)
#if defined(__ARM_PCS_VFP)
#define ABI "armeabi-v7a/NEON (hard-float)"
#else
#define ABI "armeabi-v7a/NEON"
#endif
#else
#if defined(__ARM_PCS_VFP)
#define ABI "armeabi-v7a (hard-float)"
#else
#define ABI "armeabi-v7a"
#endif
#endif
#else
#define ABI "armeabi"
#endif
#elif defined(__i386__)
#define ABI "x86"
#elif defined(__x86_64__)
#define ABI "x86_64"
#elif defined(__mips64) /* mips64el-* toolchain defines __mips__ too */
#define ABI "mips64"
#elif defined(__mips__)
#define ABI "mips"
#elif defined(__aarch64__)
#define ABI "arm64-v8a"
#else
#define ABI "unknown"
#endif
Answered By - mstorsjo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.