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.
相关问题
- Error building gcc 4.8.3 from source: libstdc++.so
- What are the recommended GNU linker options to spe
- What is the right order of linker flags in gcc?
- Why doesn't g++ -Wconversion warn about conver
- Where to get compiled version of gccxml on windows
相关文章
- Suppress “Circular dependency detected” suppress w
- gcc/g++ gives me error “CreateProcess: No such fil
- Calls that precede a function's definition can
- How can I use gcc's -I command to add recursiv
- How do I know if std::map insert succeeded or fail
- How to specify gcc flags (CXXFLAGS) particularly f
- How to force Delphi compiler to display all hints
- How to generate assembly code with gcc that can be
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.
You can try using precompiled headers. Warnings won't go away but at least the won't show up in your main compilation.
For those using CMake, you can modify your
include_directories
directives to include the symbolSYSTEM
which suppresses warnings against such headers.You can use pragmas. For example:
If you need to explicitly override a system header then you're restricted to pragmas. You can verify which includes you're using via
make depend
output.Also see diagnostic push-pop for gcc >= 4.6
#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.