Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a custom MACRO when using NDK?

Tags:

android-ndk

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!

like image 369
Loc Avatar asked Oct 26 '10 09:10

Loc


People also ask

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.

Is NDK a compiler?

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

Is NDK open source?

OpenJDK has the same code as OracleJDK, depending on what provider you're using. The key difference (as stated above) is that OpenJDK is an open source java development kit, whereas Oracle JDK is closed source.


3 Answers

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
like image 180
Moss Avatar answered Nov 04 '22 03:11

Moss


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.

like image 37
torkildr Avatar answered Nov 04 '22 02:11

torkildr


If you're talking about android makefile MACROs like

$(call my-dir)

It's exactly same as GNU makefile syntax

Gnu makefile manual

For instance:

reverse = $(2) $(1)

foo = $(call reverse,a,b)

$(warning $(foo))

results:

b a

like image 22
Jan Avatar answered Nov 04 '22 02:11

Jan