I am wondering if it is possible to have werror in gcc/g++ exclude certain files (ones that I do not have source code to modify) so that I can continue using werror in a uninhibited state.
-
1If you do not have the source code... then you should already have a library to link to. Or do you mean the header files? – Akusete Jul 26 '10 at 23:43
-
Err... if you don't have the source code, then GCC would not be complaining! – Billy ONeal Jul 27 '10 at 00:15
-
Seems to be dup of http://stackoverflow.com/questions/3308523/how-to-eliminate-external-lib-third-party-warnings-in-gcc – Dummy00001 Jul 27 '10 at 15:36
3 Answers
Use pragma directives with a newer (4.2 I think) version of gcc to turn off -Werror for certain headers prior to including them.
You might want to accept answers for your previous questions.

- 23,808
- 4
- 67
- 87
@Sam Miller already gave the reference documentation about how to do this...
You can temporarily disable -Werror
on certain warnings with #pragma GCC diagnostics warning "-W<kind>"
. For example:
#pragma GCC diagnostic push
# pragma GCC diagnostic warning "-Wreturn-type"
# pragma GCC diagnostic warning "-Wmissing-braces"
# include "legacy-crap.h"
#pragma GCC diagnostic pop
Newer gcc
will print the name of the diagnostics category in brackets as part of the the warning/error:
warning-test.c:11:1: warning: return type defaults to ‘int’ [-Wreturn-type]
or
warning-test.c:11:1: error: return type defaults to ‘int’ [-Wreturn-type]
This can be used to accurately select the exact diagnostics which should be treated as warning instead of error during processing of the third party crap you have no power to change. I do not know a short hand to disable all the warnings ("-Wall"
will not have desired effect for the above #pragma
), but I think it is also good to be explicit here.

- 4,323
- 2
- 31
- 47
My only thought is to compile the files you can modify separately with -Werror
and then link them with the other object/library files without -Werror
.

- 12,177
- 9
- 69
- 105