Search code examples
gccandroid-ndkmakefilejava-native-interfacecompiler-optimization

How to know the gcc optimization level for ndk-build


I was writing some native code on Android using NDK(jni). I want to turn off the gcc compiler optimization. For now I add LOCAL_CFLAGS += -O0 to Android.mk, I'm not sure if it is working.

I wrote some code to test the loop overhead like this:

// gettime
for(int i = 0 ; i<10000;i++)
{

}
// gettime

The time difference is too small that I'm sure that the loop has been deleted by the compiler. I can change i to a volatile variable, but I want to test if I have turned off the compiler optimization correctly.

How can I know the optimization level that is used by gcc(ndk-build), can I set make to verbose to get all the messages?

Thanks in advance.


Solution

  • See here how to disable optimizations: Android NDK assert.h problems

    Basically what you need to do is to add

    APP_OPTIM := debug
    

    to your Application.mk file