I'm trying to build a shared object with the following recipe in our Android.mk
. The shared object is based on a C++ library.
include $(CLEAR_VARS)
LOCAL_MODULE := cryptopp_shared
LOCAL_SRC_FILES := $(addprefix $(CRYPTOPP_PATH),$(CRYPTOPP_SRC_FILES))
LOCAL_CPP_FLAGS := -Wall
LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_LDFLAGS := -Wl,--exclude-libs,ALL -Wl,--as-needed
LOCAL_EXPORT_CFLAGS := $(LOCAL_CFLAGS)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/..
LOCAL_STATIC_LIBRARIES := cpufeatures
include $(BUILD_SHARED_LIBRARY)
The library builds mostly OK. Some options are not being honored, like -Wall
. Other options like -Wl,--exclude-libs,ALL
are being honored.
The docs for Android.mk is here, but it does not discuss removing or filtering options.
Why is Android's build system not honoring all of our flags?
Here is the build command we used. I build from the library's root directory:
ndk-build V=1 APP_ABI=armeabi-v7a NDK_PROJECT_PATH="$PWD"
NDK_APPLICATION_MK="$PWD/Application.mk"
The odd thing is, all of our source files are C++ and none of the source files were built with -Wall
. However, we import Android's cpufeatures library, it is one C source file, and it was built with -Wall
:
/opt/android-ndk-r16b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -MMD -MP -
MF /home/cryptopp/obj/local/armeabi-v7a/objs/cpufeatures/cpu-features.o.d -gcc-t
oolchain /opt/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/lin
ux-x86_64 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wn
o-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-
prefixes -fno-integrated-as -g -target armv7-none-linux-androideabi18 -march=arm
v7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Os -DNDEBUG -I/opt/android-ndk
-r16b/sources/android/cpufeatures -DANDROID -Wall -Wextra -Werror -D__ANDROID_
API__=18 -Wa,--noexecstack -Wformat -Werror=format-security --sysroot /opt/andr
oid-ndk-r16b/sysroot -isystem /opt/android-ndk-r16b/sysroot/usr/include/arm-linu
x-androideabi -c /opt/android-ndk-r16b/sources/android/cpufeatures/cpu-features
.c -o /home/cryptopp/obj/local/armeabi-v7a/objs/cpufeatures/cpu-features.o
Given I used LOCAL_CPP_FLAGS := -Wall
I would think the opposite would happen - all C++ source files would build with -Wall
, and the one C file would build without.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…