views:

432

answers:

5

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.

+1  A: 

You can try using precompiled headers. Warnings won't go away but at least the won't show up in your main compilation.

Pablo Santa Cruz
This might actually be a good idea. Third-party includes don't change every day.
AdSR
Exactly. Although I haven't used them that much in Linux, they work pretty well on Visual Studio.
Pablo Santa Cruz
+1  A: 

#pragma are instructions to the compiler. you can set something before the #include and disable it after.

You can also do it at the command line.

Another GCC page specifically on disabling warnings.

I would go for the option of using #pragma's within the source code, and then providing a sound reason (as a comment) of why you are disabling the warnings. This would mean reasoning about the headers files.

GCC approaches this by classifying the warning types. You can classify them to be warnings or to be ignored. The previously linked articles will show you which warnings are may be disabled.

Note: you can also massage the source code to prevent certain warnings by using attributes; however, this bind you quite closely to GCC.

Note2: GCC also uses the pop/push interface as used in microsoft's compiler -- Microsoft disables warnings through this interface. I suggest you investigate this further , as I do not know if it is even possible.

Hassan Syed
I considered pragmas but if I suppress a warning before including a header, how do I set it back to the *previous state* after #include? I want to see all warnings for the project code (helped me already a few times) but have control from command line.
AdSR
added more info.
Hassan Syed
A: 

There must be reasons for those warnings. These will either be caused by errors in your code that uses the library, or by errors in the library code itself. In the first case, fix your code. In the second case, either stop using the library or if it is FOSS code, fix it.

anon
+1 for good advice :D but he is asking how to do something specific :D
Hassan Syed
+3  A: 

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.

AdSR
+8  A: 

You may try to include library headers using -isystem instead -I. This will make them "system headers" and GCC won't report warnings for them.

Phi

related questions