How to suppress GCC warnings from library headers?

Viewed 58427

I have a project that uses log4cxx, boost, etc. libraries whose headers generate lots of (repetitive) warnings. Is there a way to suppress warnings from library includes (i.e. #include <some-header.h>) or includes from certain paths? I'd like to use -Wall and/or -Wextra as usual on project code without relevant info being obscured. I currently use grep on make output but I'd like something better.

10 Answers

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.

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.

Putting the following

#pragma GCC system_header

will turn off GCC warnings for all following code in this file.

Another way to do it is, in the makefile, to tell the compiler to ignore warnings for the specific folder:

$(BUILD_DIR)/libs/%.c.o: CFLAGS += -w
Related