My project uses -Werror to turn GCC 11.3.0 g++ warnings to errors and stop the build. But a 3rd party header file we need to include causes a bunch of warnings to be issued by the compiler.
I was hoping there is a way to turn off -Werror for that 1 include file. Maybe a #pragma I can issue just before and just after that header file is invoked?
However, it does not seem to be the case. Best I can find is to disable individual warnings with #pragma GCC diagnostic ..., which would make me list all of the warnings that this header file causes.
Is that really the case or did I miss something obvious?
Edit:
Turns out some warnings/errors can be disabled, but others cannot. For example, this works to remove the signed/unsigned warnings:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <problematic_include.hpp>
#pragma GCC diagnostic pop
But this does not work:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#include <problematic_include.hpp>
#pragma GCC diagnostic pop
...to remove the error about error: ignoring ‘#pragma _CVUI_COMPILE_MESSAGE ’ [-Werror=unknown-pragmas].
I tried to not name the 3rd party library that caused this, but it turns out in this case the library itself provides a solution to the problem.
The library is CVUI, which provides some simple GUI functionality based on OpenCV. It is a header-only library. Turns out it has a macro called CVUI_DISABLE_COMPILATION_NOTICES which prevents the problematic #pragma line that was causing g++ to stop compiling.
In the end, as ugly as this is, here is the solution I chose:
#define CVUI_IMPLEMENTATION
#define CVUI_DISABLE_COMPILATION_NOTICES
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-compare"
#include "cvui.h"
#pragma GCC diagnostic pop
This way the cvui.h file can be successfully included from within a project that uses -Wall -Wextra -Werror.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With