7

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.

3
  • @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, 2019 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, 2019 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).
    – user313992
    Oct 25, 2019 at 22:02

2 Answers 2

8

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.

2
  • -fcompare-debug-second also inhibits messages coming from #pragma message. How to keep #pragma message messages?
    – pmor
    Nov 4, 2020 at 22:04
  • #pragma message generates a note message. Consider using #warning instead.
    – user313992
    Nov 6, 2020 at 1: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.

1
  • 2
    But I don't want to suppress warnings.
    – Jennifer
    Oct 30, 2019 at 4:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .