Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 428
Rémi Avatar asked Jun 16 '11 15:06

Rémi


People also ask

What compiler does Android NDK use?

The NDK itself invokes a customized cross-compiler built on the arm-eabi-gcc compiler.

How do I know if Android NDK is installed?

With a project open, click Tools > SDK Manager. Click the SDK Tools tab. Select the NDK (Side by side) and CMake checkboxes. Note: If you have an NDK installed in the ndk-bundle folder, it appears in the list with the label NDK.

What is .MK file in Android?

Overview. The Android.mk file resides in a subdirectory of your project's jni/ directory, and describes your sources and shared libraries to the build system. It is really a tiny GNU makefile fragment that the build system parses once or more.

How do you use NDK?

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.


2 Answers

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.

like image 145
chvor Avatar answered Oct 04 '22 22:10

chvor


Short answer: #ifdef ANDROID .

The ANDROID macro is defined for you in build-module.mk (part of the standard build system):

# always define ANDROID when building binaries # LOCAL_CFLAGS := -DANDROID $(LOCAL_CFLAGS) 
like image 22
Martin Stone Avatar answered Oct 04 '22 21:10

Martin Stone