Reputation: 943
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:
#if TEST_FOO
// do something <- this never gets reached
#endif
Even if in the Android.mk file I place secondfile.cpp after main.cpp:
LOCAL_SRC_FILES := main.cpp \
secondfile.cpp
Is there a way to #define values in Android NDK inside the actual code?
Upvotes: 8
Views: 6837
Reputation: 2699
Put it in the header file and include the header file in every .c file where you want it to be defined.
Upvotes: 0
Reputation: 60681
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 Android.mk
:
LOCAL_CPPFLAGS := -DTEST_FOO=1
Upvotes: 17