Disable -Wall compiler warnings in a Qt project?

Cory Klein picture Cory Klein · Sep 7, 2013 · Viewed 16.6k times · Source

I am compiling a 3rd party library and don't care to fix the warnings present in the library, but I don't want them polluting the Issues pane in Qt Creator.

I've tried following the advice here, but there is no compiler flag to disable -Wall after it has been enabled, such as with -Wno-enum-compare.

After reading this, I tried removing the flag like so:

CFLAGS -= -Wall

But that didn't work either. So I tried this advice:

QMAKE_CXXFLAGS_WARN_OFF -= -Wall

Still nothing.

So I looked in the generated Makefile and found this:

CFLAGS        = -pipe -g -fPIC -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS      = -pipe -g -fPIC -Wall -W -D_REENTRANT $(DEFINES)

So I tried removing the flag from those two variables:

CFLAGS -= -Wall
CXXFLAGS -= -Wall

Still nothing. How are you supposed to remove this compiler flag?!

Answer

Cory Klein picture Cory Klein · Sep 7, 2013

The simplest solution is:

CONFIG += warn_off

Thanks to peppe in comments.

Explanation

The -Wall flag gets inserted into the Makefile by these two variables:

QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS_WARN_ON

So to remove -Wall, you need to remove it from both of those variables.

QMAKE_CFLAGS_WARN_ON -= -Wall
QMAKE_CXXFLAGS_WARN_ON -= -Wall

warn_off does just that.