Issue
I've taken over a large and very old project recently. It compiles without problems, but since the code is so old and the former developers weren't always doing things the way they were supposed to, I get a lot of warnings with a modern compiler.
Now I change parts of the code and sometimes introduce an error. When I recompile the project, a lot of warning output is happening, and at the end of the output, I see a message like this:
SomeFile.C:3426:51: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
SomeCode("Some String");
^
SomeFile.C:3429:55: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
SomeCode("Some Other String");
^
make[2]: *** [SomeFile.o] Error 1
make[2]: Leaving directory `/some/path/of/a/source/directory/somesubdirectory'
make[1]: *** [somesubdirectory] Error 2
make[1]: Leaving directory `/some/path/of/a/source/directory'
make: *** [directory] Error 2
BUILD FAILED (exit value 2, total time: 2s)
And a lot of warnings above that (I just showed two of a list of dozens).
The real error is displayed hundreds of lines above that and reads:
SomeFile.C: In function 'void someFunction()':
SomeFile.C:891:5: error: 'someIdentifier' was not declared in this scope
someIdentifier->someMoreStuff->someMethod(someArgs);
^
My problem now is to find the error message. It would be easy if I could turn off the warnings because then the error message would be the last thing printed.
So is there a way to tell the compiler not to give out any warnings or at least print the error messages at the very end (that would be enough to solve my problem)?
I want to solve this issue with as little patch work as possible, so it is more or less out of the question to fix all code occurrences issuing the warnings, especially since I am about to throw away large parts of it in the end and just keep one feature I want to extract.
I can, however, change all files (maybe inserting a #pragma
or #define
or similar at the beginning using find
and sed
), I also can patch the Makefile
s in all directories. It would be nice, however, to be able to switch the solution off and on without having to patch too much (if possible, I don't want to demand too much).
I found and tried some information on suppressing warnings, e.g., this here, but using options -i
(or -isystem
) or #pragma GCC system_header
seems not to work in my case, probably because the file being warned about is the one given on the command line, not an included file. The #pragma
is being warned about itself because of this.
Solution
You may set gcc -w
to inhibit all warning messages.
Answered By - Peixu Zhu Answer Checked By - Mary Flores (WPSolving Volunteer)