4

I have some open source library files in my project (e.g: http://nothings.org/stb_vorbis/stb_vorbis.c). -Wall option is enabled in my Android.mk file. During compilation several warnings are generated in stb_vorbis.c.

warning: unused variable <var>
warning: statement with no effect
warning: <var> defined but not used
warning: <var> may be used uninitialized in this function

For some reason I do not want to modify stb_vorbis.c but still want the -Wall option to be available for my own source files. Is there any way to disable -Wall option for specific files/folder ?

gmuhammad
  • 1,434
  • 4
  • 25
  • 39

4 Answers4

6

Is there any way to disable -Wall option for specific files/folder ?

I do not believe there is any gcc option that could be used to achieve this. You need to change your Makefile that you used to compile the problematic source files.

You could do something like

CFLAGS:=$(filter-out -Wall, $(CFLAGS))

in the Makefile for stb_vorbis, if your make supports filter-out function.

Also you could write a specific rule for that stb_vorbis.c:

STB_VOBIS_CFLAGS:=$(filter-out -Wall, $(CFLAGS))
stb_vorbis.o: stb_vorbis.c ...
        $(CC) $(STB_VOBIS_CFLAGS) -o $@ -c $<
Lee Duhem
  • 14,695
  • 3
  • 29
  • 47
  • I don't get your point. Will it exclude only for stb_vorbis.c or will be applied overall? I have only one make file for all source files. – gmuhammad Mar 18 '14 at 07:53
  • @gmuhammad Do you have a Makefile to compile files from `stb_vorbis`? If you have one, put that call to `filter-out` in that Makefile. – Lee Duhem Mar 18 '14 at 07:56
  • I don't have separate make file for stb_vorbis – gmuhammad Mar 18 '14 at 08:15
  • @gmuhammad Then you may need to write specific rule for `stb_vorbis.c`. – Lee Duhem Mar 18 '14 at 08:18
  • Do you mean to create separate Makefile for stb_vorbis.c and include some rule? – gmuhammad Mar 18 '14 at 08:20
  • 1
    @gmuhammad No, not separate Makefile. Just add a new rule for `stb_vorbis.c` in your current Makefile. – Lee Duhem Mar 18 '14 at 08:23
  • 1
    using -isystem is also helpful sometimes see: http://stackoverflow.com/questions/15053776/how-do-you-disable-the-unused-variable-warnings-coming-out-of-gcc – gmuhammad Mar 24 '14 at 07:10
2

Although there's no way to turn off -Wall with one option, you can turn off specific warnings in GCC, using the -Wno-* for warning *. So, for example, to suppress the unused variable warning you can add -Wno-unused-variable. See http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html for more information on different warning options.

So for example you could use target-specific variables, like:

stb_vorbis.c: CFLAGS += -Wno-unused-variable
MadScientist
  • 92,819
  • 9
  • 109
  • 136
0

Using target-specific variables you can append the -w option to inhibit all warning messages for stb_vorbis.c file:

stb_vorbis.o: CFLAGS += -w

or for an entire directory:

third_party/%.o: CFLAGS += -w

A general rule of thumb is that if you have two or more mutually exclusive options, gcc will generally take later options over earlier ones.

manlio
  • 18,345
  • 14
  • 76
  • 126
0

using -isystem was the working solution for me.

For example, instead of -IC:\\boost_1_52_0, say -isystem C:\\boost_1_52_0.

Described in detail in the following thread:

How do you disable the unused variable warnings coming out of gcc in 3rd party code I do not wish to edit?

Thank you @lee-duhem for your kind and useful suggestions.

gmuhammad
  • 1,434
  • 4
  • 25
  • 39