Android NDK #define Problems


When I add #define to either main.cpp or one of my headers called from main.cpp, it does not seem to be defined in other files.

For example, in main.cpp I might do something like:

#define TEST_FOO 1

Then in one of my other files, for example secondfile.cpp, TEST_FOO is ignored as if it was never defined:

// do something <- this never gets reached

Even if in the file I place secondfile.cpp after main.cpp:

LOCAL_SRC_FILES : main.cpp \

Is there a way to #define values in Android NDK inside the actual code?


That is correct. The compiler only knows about one source file at a time. When you compile secondfile.cpp, it has completely forgotten about anything you may have defined in main.cpp.

If you want a #define to be visible in all your source files, you need to put it in a header which is included by all your files. Or, pass it on the command line; you can do this by adding something like this to your


Answered By – Graham Borland

Leave a Comment