简体   繁体   中英

Detect stdint.h and C++11 on android NDK

I found somewhere that i could detect C++11 using the following line :

#if __cplusplus <= 199711L

I'm using this to conditionally defined fixed-width types such as int32_t or uchar16_t, etc...

The problem is that when using the android NDK, __cplusplus is defined as 1 . Is there a more portable way to detect C++11 and the presence of stdint.h to avoid redefinitions ?

Thank you.

For me it always works:

$ CXX=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++
$ $CXX -x c++ -E -dM /dev/null | grep __cplusplus
#define __cplusplus 199711L
$ $CXX -x c++ -std=c++11 -E -dM /dev/null | grep __cplusplus
#define __cplusplus 201103L

The same for LLVM toolchain:

$ CXX="$NDK/toolchains/llvm-3.5/prebuilt/darwin-x86_64/bin/clang++ -target armv7-none-linux-androideabi"
$ $CXX -x c++ -E -dM /dev/null | grep __cplusplus
#define __cplusplus 199711L
$ $CXX -x c++ -std=c++11 -E -dM /dev/null | grep __cplusplus
#define __cplusplus 201103L

I've tried it with NDK r10d and r10e, and it works in both of them, so there is definitely something wrong with your setup. I could say more if you'd provide minimal project where such problem exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM