tags:

views:

18

answers:

2

I need some custom MACROs in my NDK projects however I have no ideal how to add and I found no answers Could anyone please help? Many thanks!

A: 

If you understand you correctly, you need to look at how the C Preprocessor works.

Do you have any experience in writing C/C++-programs? First off, you should be really picky on what parts of your application you write in native code. Also, you need to keep in mind that the native code will behave totally different when it comes to memory allocation and such, so this really isn't the place for guesswork.

Spend some time getting to know C/C++, design your application wisely so that the parts you want to write in native code is clearly defined, and that it doesn't increase the chance of your application crashing. I'm guessing most projects can do without an native application part, so if you're using it, and don't know exactly what you're doing, you should really re-asses whether it's the right thing to do or not.

torkildr
I'm doing a migration and I'm a newbie for android,thanks for your advising!
Loc
A: 

If you would like to add a special definition when compiling your NDK code (jni) add the following into your Android.mk:

LOCAL_CFLAGS    := -DMYDEFINE

This will define the Macro MYDEFINE in your c/c++ code. Here an example

#ifdef MYDEFINE
// We build the project with this special macro
#else
// We build without setting the macro in the LOCAL_CFLAGS
#endif
Moss
It works perfectly!Thank you!
Loc
Nice that it worked :P So you might accept the answer hehe :P
Moss