1

I am using -Werror flag to treat all warnings as errors in my code. However, I would like compile warnings issued from code to still be treated as warnings. A GCC option for this is -Wno-error=cpp which works correctly, however clang option is -Wno-error=#warnings which I don't know how to pass to clang from Android.mk.

I've tried this:

ifeq "$(findstring clang,$(NDK_TOOLCHAIN_VERSION))" "clang"
    LOCAL_CFLAGS += -Wno-error=#warnings
endif

and this (as suggested in this SO answer):

ifeq "$(findstring clang,$(NDK_TOOLCHAIN_VERSION))" "clang"
    LOCAL_CFLAGS += -Wno-error=\#warnings
endif

However, both versions treat # as beginning of comment and ndk-build passes -Wno-error= to compiler (i.e. everything after = is ignored) - I inspected that with ndk-build -n.

I even tried

ifeq "$(findstring clang,$(NDK_TOOLCHAIN_VERSION))" "clang"
    LOCAL_CFLAGS += -Wno-error=\\#warnings
endif

which produces -Wno-error=\ compiler flag.

How to properly pass this compiler flag to clang from Android.mk file?

I am using NDK r12b.

EDIT: I even tried this:

ifeq "$(findstring clang,$(NDK_TOOLCHAIN_VERSION))" "clang"
    VAR=\#warnings
    $(info VAR is '$(VAR)')
    LOCAL_CFLAGS += -Wno-error=$(VAR)
endif

and ndk-build first outputs message VAR is '#warnings' yet compiler arguments contain -Wno-error=. This is obviously an NDK issue.

Community
  • 1
  • 1
DoDo
  • 2,248
  • 2
  • 22
  • 34

1 Answers1

1
LOCAL_CFLAGS += -Wno-error=\#warnings

is almost there. But to get make to treat the \ as escaping the # it needs to be in quoted context.

Makefile

CXX := clang++

CXXFLAGS += "-Wno-error=\#warnings"

hello: HelloWorld.o
    $(CXX) -o $@ $^ 

Build and run:

$ make && ./hello
clang++ "-Wno-error=#warnings"   -c -o HelloWorld.o HelloWorld.cpp
clang++ -o hello HelloWorld.o
Hello World
Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
  • 1
    Tried that. In the command line ends up `"-Wno-error=`. This appears to be a NDK issue, not a makefile problem. I've reported the issue [here](https://github.com/android-ndk/ndk/issues/161). – DoDo Jul 15 '16 at 23:34