Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

Does Android compiler honor -Wall?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's a mere typo, you need LOCAL_CPPFLAGS, only one _ there.

As for cpu-features.c, it receives -Wall because $(NDK_ROOT)/sources/android/cpufeatures/Android.mk requires this in LOCAL_CFLAGS.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...