6

When I compile a C (no pluses) program using GCC, there are several levels of messages possible, like warning, error, and note. The note messages are useless and distracting. How do I make them go away using the command line? (I don't use any sort of IDE.)

Example: /home/user/src9/AllBack3.c:129:9: note: each undeclared identifier is reported only once for each function it appears in.

Jennifer
  • 259
  • 2
  • 8
  • @mosvy, the man page makes `-fcompare-debug-second` sound a bit scary though: "When this option is passed to the compiler driver, it causes the first compilation to be skipped, which makes it useful for little other than debugging the compiler proper." – ilkkachu Oct 19 '19 at 16:10
  • @mosvy I guess -fcompare-debug-second will have to do, if there's nothing else. If you put that in the form of an answer, I'll accept it. – Jennifer Oct 20 '19 at 14:31
  • @ilkkachu notice that the second run of the compiler done by `-fcompare-debug` has nothing to do with the multiple compilation or optimization passes gcc may do -- as far as I can gather (I haven't used it myself), it's just a feature to debug the compiler itself (and create actionable bug reports). –  Oct 25 '19 at 22:02

2 Answers2

7

Pass the -fcompare-debug-second option to gcc.


gcc's internal API has a diagnostic_inhibit_note() function which turns any "note:" messages off, but that is only serviceable via the unexpected -fcompare-debug-second command line switch, defined here.

Fortunately, turning notes off is its only effect, unless the -fcompare-debug or the -fdump-final-insns options are also used, which afaik are only for debugging the compiler itself.

  • `-fcompare-debug-second` also inhibits messages coming from `#pragma message`. How to keep `#pragma message` messages? – pmor Nov 04 '20 at 22:04
  • `#pragma message` generates a note message. Consider using `#warning` instead. –  Nov 06 '20 at 01:13
-3

You can use -w which also suppresses warnings.

For GCC, -w will not suppress the note you mentioned, probably because it is shown instead of another error. clang's -w on the other hand suppresses that too.

V13
  • 4,551
  • 1
  • 15
  • 20