What the difference about LOCAL_CFLAGS vs APP_CFLAGS ? - android-ndk

In the Android.mk, I can use LOCAL_CFLAGS += ... to specify flag to compiler. also, I can use: ./ndk-build APP_CFLAGS += ....
What's the difference between these two flags?

LOCAL_CFLAGS is applied to the current module, and is undefined after an include $(CLEAR_VARS).
APP_CFLAGS is applied to all modules.

Related

How do you add APP_CFLAGS to an android makefile

I was able to successfully pass in APP_CFLAGS via eclipse through via the settings' ndk-build command as
ndk-build -B NDK_DEBUG=1 APP_CFLAGS=-DTEST
I have now switched to Android studio and was trying to do it directly in the makefile with the following, but its not taking:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
APP_CFLAGS += -DTEST
LOCAL_SRC_FILES:= test.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
It builds fine, but my TEST variable is never set in the C++ code.
How can I add it to the makefile?
Or, How can I add it to Android Studio project settings?
You could use LOCAL_CFLAGS for C/C++ code additional flags or LOCAL_CPPFLAGS for C++ code in Android build system.
LOCAL_CFLAGS := -DTEST=1

What is it for the pedantic flag in LOCAL_CFLAGS

What is the of the "-pedantic" flag in LOCAL_CFLAGS for Android.mk builds?
And is there any place to find all the possible flags and their meaning?
thanks
I'm not familiar with the Android build systems, but CFLAGS is usually a variable describing flags to pass to the C compiler.
If you use the clang or GCC compiler families, the -pedantic flag enables particularly "picky" warnings about your code. See the option index and the warnings section for GCC.

Warning : Overriding commands for target Android Makefile

I've got an issue building my C++ code using NDK r9d, since I try to compile C files using C++ compiler (G++) I've got this warnings :
C:/Android/ndk/build/core/build-binary.mk:393: warning: overriding commands for target
C:/Android/ndk/build/core/build-binary.mk:391: warning: ignoring old commands for target
Before I didn't need to compile with C++ 11 and my C files was compiled with GCC, I had no problems, but since I had LOCAL_CPP_EXTENSION := .cpp .c, this warnings appears (only for C files).
I found that someone else had the same problem (Overriding commands for target Android Makefile) but didn't get any answer.
Here is my files :
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
MY_INC_PATH := ../../..
LOCAL_MODULE := test
LOCAL_CFLAGS := -Werror
LOCAL_CPPFLAGS := -std=c++11
LOCAL_LDLIBS := -ldl -llog -lGLESv1_CM
LOCAL_C_INCLUDES := \
$(MY_INC_PATH)
MY_SRC_PATH := ../../../..
LOCAL_CPP_EXTENSION := .cpp .c
LOCAL_SRC_FILES := \
$(MY_SRC_PATH)/XXX.c \
$(MY_SRC_PATH)/YYY.cpp \
$(MY_SRC_PATH)/ZZZ.cpp
include $(BUILD_SHARED_LIBRARY)
I use NDK r9d and compile with G++ 4.8 and C++ 11 activated. Thanks for your help.
As of r9d, NDK does not provide methods to unassociate .c files from C compiler. You can redefine $$(TARGET_CC), and also set LOCAL_CFLAGS += -std=c++11, and not set LOCAL_CPP_EXTENSION to include .c, but that would be a hack, anyways. So if you cannot rename the files, and do not want to hack your NDK, the cleanest solution would be to simply ignore the warning.

NDK build - specify linker settings per architecture

My Application.mk is set to build arm as well as x86 shared libraries:
APP_ABI :- armeabi-v7a x86
I have prebuilt openssl static libraries:
libcrypto_v7a.a
libcrypto_x86.a
libssl_v7a.a
libssl_x86.a
These files have been copied to jni/inc directory:
Would appreciate your help in setting up Android.mk such that it picks up proper library to link with:
LOCAL_LDLIBS := -llog -L$(LOCAL_PATH)/inc/ -lcrypto_v7a -lssl_v7a
or
LOCAL_LDLIBS := -llog -L$(LOCAL_PATH)/inc/ -lcrypto_x86 -lssl_x86
Perhaps there is a $(ARCH) kind of variable defined that I could use to my advantage:
LOCAL_LDLIBS := -llog -L$(LOCAL_PATH)/inc/ -lcrypto_$(ARCH) -lssl_$(ARCH)
What about using ifeq and TARGET_ARCH?
LOCAL_LDLIBS := -llog -L$(LOCAL_PATH)/inc/
ifeq ($(TARGET_ARCH),arm)
LOCAL_LDLIBS += -lcrypto_v7a -lssl_v7a
else
ifeq ($(TARGET_ARCH),x86)
LOCAL_LDLIBS += -lcrypto_x86 -lssl_x86
endif
endif
Another alternative is:
MY_LDLIBS_arm := -lcrypto_v7a -lssl_v7a
MY_LDLIBS_x86 := -lcrypto_x86 -lssl_x86
MY_LDLIBS_mips := ...
LOCAL_LDLIBS += $(MY_LDLIBS_$(TARGET_ARCH))
Which is easier to read and write.

Disable all warning during ndk-build

I'm trying to disable all warnings during the 'ndk-build' process for compiling CPP code to be used with JNI on Android.
I'm using LOCAL_CFLAGS := -Wno-error with not success.
Any ideas?
Thanks
OK. Got it. Put this line in your Android.mk file.
LOCAL_CFLAGS := -w
Hope it helps

Resources