gmuhammad
gmuhammad

Reputation: 1438

gcc disable -Wall flag for specific files/folders

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 ?

Upvotes: 4

Views: 5755

Answers (4)

gmuhammad
gmuhammad

Reputation: 1438

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.

Upvotes: 0

manlio
manlio

Reputation: 18962

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.

Upvotes: 0

MadScientist
MadScientist

Reputation: 100966

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

Upvotes: 2

Lee Duhem
Lee Duhem

Reputation: 15121

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 $<

Upvotes: 6

Related Questions