Hi,
Can someone tell me how to suppress all the warnings g++ produces? Not specific warnings : I know how to do that. I want to not see any warnings at all when I build.
Thanks.
A short expert summary and practical options tied to the thread
The compiler does offer a way to hide every warning, but warnings exist because the compiler is trying to point out risky or likely-buggy constructs. Several members in this thread raised that concern (, and ); the GCC manual describes warnings as diagnostics for constructions that are “risky or suggest there may have been an error.” (gcc.gnu.org)
Quick (last‑resort) escape: inhibit all warnings
GCC’s global “suppress all warnings” switch will stop the compiler printing any warnings. For a one-off, emergency build (not committed into the codebase), that is the simplest approach. The option is documented in the GCC diagnostics section. (gcc.gnu.org)
g++ -w -o program prog.cpp Safer, immediately‑useful workflows
Redirect compiler diagnostics to a file and split warnings/errors for triage instead of erasing them. For example (shell redirection + simple filters):
g++ -c src/*.cpp 2> build.log
grep -i 'warning:' build.log > warnings.txt
grep -i 'error:' build.log > errors.txt Shell redirection semantics (2> to capture stderr, 2>&1 to combine) are standard bash behavior. This preserves all output for later cleanup while letting a build step focus on errors first. (gnu.org)
Targeted suppression for third‑party noise
When warnings come from specific headers, local suppression via compiler pragmas is preferable to a global switch. Use GCC’s diagnostic pragmas to push/pop state and ignore only the named warning around the include. That keeps the rest of the codebase visible and maintainable. (gcc.gnu.org)
Practical advice tied to the thread
As noted, compiler flags can silence diagnostics; as suggested, redirecting and filtering helps focus on errors. Use the global suppression only as a temporary, emergency measure. For ongoing work on a legacy project, capture warnings into a file, triage the most frequent/significant ones, and progressively clean them up rather than permanently hiding the compiler’s feedback. (gcc.gnu.org)
Jump to Post— Nick Evan 4,005Why on earth would you not want to see warnings? You know that 99% of the warnings are actually code-errors that the compiler can compile right?
Jump to Post— tux4life 2,072Hi,
Can someone tell me how to suppress all the warnings g++ produces? Not specific warnings : I know how to do that. I want to not see any warnings at all when I build.Thanks.
I have to agree with niek_e, since there's really no reason to not want …
Jump to Post— daviddoria 334I agree that it's generally a very bad idea - but if you DO have a good reason, compile with -Wno
Why on earth would you not want to see warnings? You know that 99% of the warnings are actually code-errors that the compiler can compile right?
Hi,
Can someone tell me how to suppress all the warnings g++ produces? Not specific warnings : I know how to do that. I want to not see any warnings at all when I build.Thanks.
I have to agree with niek_e, since there's really no reason to not want to see the warnings.
Or are you really begging for bugs in your program?
A warning should be taken seriously, because it informs you about potential bugs in your program.
And we don't want that right?
If you find me a good reason, please tell me.
But I'm sure you just can't find one.
IMO you should always compile with all warnings on. (-Wall).
I agree that it's generally a very bad idea - but if you DO have a good reason, compile with -Wno
g++ --ostrich-head-in-sand prog.cpp
Please tell us the name of the software you're working on, so we know to avoid it in future. I don't want to be anywhere near this train-wreck of a methodology.
I want to not see any warnings at all when I build.
I haven't seen many warnings that were so asinine they could be completely ignored. Disabling warnings just so you can get a clean compile is not a recommended practice because fixing them almost always makes your code better.
Separating warnings and errors makes sense, and that's the only time I can think of where you might want to use -Wno. But a better way to split up the errors and warnings is redirecting the output of the compiler to a file and then grepping the file on warnings and then errors. That way you don't lose any output and still have a way of focusing on one or the other.
How aggressive...
Anyway, thanks daviddoria. I'll compile with -Wno.
I'm gonna bookmark this thread so I can refer to it, when your next question would have been solved by reading the error messages.
How aggressive...
It's a sign of how much everyone cares. A good friend will try to stop you from doing something dumb. ;) Out of curiosity, why do you want to disable all warnings?
It's a sign of how much everyone cares. A good friend will try to stop you from doing something dumb. ;) Out of curiosity, why do you want to disable all warnings?
Because I don't really want to wade through 100s of warnings (I did not write the program, I am just taking over.) looking for a single error and I wan't able to grep stderr. And I am frustrated when it does not build because I am wasting more time trying to get it built when I have deadlines to meet.
Then again, you people are right, In a perfect scenario, I'd take some time and would take care of every warning. But as of when I asked the question, I was in need of a quick solution : -Wno.
Luckily, Not everyone were so concerned with the purity of it and mentioned the solution for which I am grateful.
I did not write the program, I am just taking over.
All the more reason to clean up the warnings too. They will just keep getting in your way, and if you ignore them, one day you will get bitten by whatever they were trying to warn you about.
In a perfect scenario, I'd take some time and would take care of every warning.
In a perfect scenario there would be no errors or warnings. In reality, shipping your code without a clean compile is no different from shipping your code without testing it. I sympathize with you about being under the gun, but producing shit to save time doesn't make you look better than slipping a deadline and producing something of higher quality.
But as of when I asked the question, I was in need of a quick solution : -Wno.
Code quality is the worst place to cut corners. I've pushed back deadlines to get a clean compile before, because I've also been burned by shelving 'minor warnings' to meet a deadline. I kind of hope that your quick solution blows up in your face, because you seem hell bent on learning the hard way instead of listening to others who already learned the hard way.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.