Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable -Wall compiler warnings in a Qt project?

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

like image 835
Cory Klein Avatar asked Sep 06 '13 22:09

Cory Klein


People also ask

How do I turn off compiler warning?

Turn off the warning for a project in Visual StudioSelect the Configuration Properties > C/C++ > Advanced property page. Edit the Disable Specific Warnings property to add 4996 . Choose OK to apply your changes.

How do I stop a GCC warning?

To suppress this warning use the unused attribute (see Variable Attributes). This warning is also enabled by -Wunused , which is enabled by -Wall . Warn whenever a static function is declared but not defined or a non-inline static function is unused.

Can compiler warnings be ignored?

Unlike compilation errors, warnings don't interrupt the compilation process. They are not errors from the viewpoint of a programming language, but they may be software bugs. However, many compilers can be customized so that their warnings don't stop the compilation process. Warnings must not be ignored.


2 Answers

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.

like image 173
Cory Klein Avatar answered Sep 22 '22 06:09

Cory Klein


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.

like image 29
lpapp Avatar answered Sep 24 '22 06:09

lpapp