How to suppress GCC warnings from library headers?
I found the trick. For library includes, instead of -Idir
use -isystem dir
in the makefile. GCC then treats boost etc. as system includes and ignores any warnings from them.
For those using CMake, you can modify your include_directories
directives to include the symbol SYSTEM
which suppresses warnings against such headers.
include_directories(SYSTEM "${LIB_DIR}/Include")
^^^^^^
You can use pragmas. For example:
// save diagnostic state
#pragma GCC diagnostic push
// turn off the specific warning. Can also use "-Wall"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>
// turn the warnings back on
#pragma GCC diagnostic pop
You may try to include library headers using -isystem
instead of -I
. This will make them "system headers" and GCC won't report warnings for them.