How to detect compilation by Android NDK in a C/C++ file?

前端 未结 3 1806
梦毁少年i
梦毁少年i 2020-12-24 04:53

Is there a preprocessor macro that will let me know NDK is compiling my code? I could manually define my own, but I\'d rather not if possible.

3条回答
  •  伪装坚强ぢ
    2020-12-24 05:38

    It is #ifdef __ANDROID__ as seen by running the preprocessor:

    ~$ /usr/local/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc -E -dM - < /dev/null | grep -i android
    

    The output is:

    #define __ANDROID__ 1
    

    No need to depend on defining stuff in your project especially if you're skipping the NDK build system.

提交回复
热议问题