Disable -Wall compiler warnings in a Qt project?

19.1k Views Asked by At

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?!

2

There are 2 best solutions below

2
On

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.

0
On

As "peppe" also noted in the comment, the Qt'ish way is this according to the documentation below: CONFIG += warn_off/on

warn_on: The compiler should output as many warnings as possible. This is ignored if warn_off is specified.

warn_off: The compiler should output as few warnings as possible.

The CONFIG documentation can be found in here.

The QMAKE_CXXFLAGS_WARN_OFF/ON variables do not need to be set explicitly as they are handled by qmake.