which macros does the Android NDK gcc define?

I’m working with a lot of cross-platform C code these days, and I find that when porting, its always best to use the macros that are automatically defined by the compiler for that platform. I’ve gotten very used to using __APPLE__ and _WIN32 (arg, yes, not WIN32 as we’d like it), then of course there is __gnu_linux__ for the OS and __linux__ for the kernel. No this is not RMS polemics, this is important, especially since there is now Debian GNU (with a Hurd kernel) and Debian GNU/kFreeBSD (no Linux there). And of course, the main feature of this post: Android.

Android uses the Linux kernel, but is definitely not GNU. The only GNU part of Android I’ve seen is the compiler: gcc.

So what macros does the Android gcc define? I wanted to know, so I ran a little test:

#include 

int main(void)
{
#ifdef __ANDROID__
    printf("__ANDROID__\n");
#endif
#ifdef ANDROID
    printf("ANDROID\n");
#endif
#ifdef android
    printf("android\n");
#endif
#ifdef __linux__
    printf("__linux__\n");
#endif
#ifdef __gnu_linux__
    printf("__gnu_linux__\n");
#endif
}

I ran that thru the cpp by running /usr/local/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc --sysroot=/usr/local/android-ndk/platforms/android-8/arch-arm/ -E -o /tmp/test.E /tmp/test.c and got:

...[snip]
int main(void)
{

    printf("__ANDROID__\n");
# 15 "/tmp/test.c"
    printf("__linux__\n");




}

About these ads

2 responses to “which macros does the Android NDK gcc define?

You must be logged in to post a comment.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: