For example I'm building project which consist of several *.cpp files and I need to supress warning only from some of this files. I use Makefile that used in Eclipse project.
How can I do it?
Update:
Seems Diagnostic Pragmas used for that:
For example I'm building project which consist of several *.cpp files and I need to supress warning only from some of this files. I use Makefile that used in Eclipse project.
How can I do it?
Update:
Seems Diagnostic Pragmas used for that:
It depends how you're building your project, and which compiler. I'm assuming you're on Linux and you're using GCC. If not, similar techniques work for Visual Studio and other compilers too.
If you have a Makefile
that you can easily modify, you can supply different compiler flags to build each file. Disabling a particular warning is as easy as adding a -Wno-<warning-name>
to the build line, for example: -Wno-unused-local-typedefs
.
If you can't easily modify your makefile, you can place #pragma
s into your source code directly. For example, you can add a line like this to the top of the C++ file:
#pragma GCC diagnostic ignored "-Wno-unused-local-typedefs"
Of course, the real solution is to fix the warnings. There are very few warnings that aren't worth heeding: Often ignoring warnings will cause you more pain in the long run!
To disable all warnings you can
# Makefile
# disable all warnings
CXXFLAGS += -w
To disable warnings for a specific *.cpp
file, try assigning target-specific variables for the relevant object file:
# Makefile
# disable warnings on foobar.cpp
foobar.o: CXXFLAGS += -w
References: