How do I disable g++ displaying notes for errors?

9,821

Solution 1

The compiler will not do this for you, but (so far...) the compiler developers are following a longstanding (30+ year) convention adapted from other compilers which gives the essential information on the first line, using error: or warning: to mark the warning. If you grep stderr for those, you will see the minimal warning/error information.

grep is a good starting point (and "grep -n" output is useful by itself). These messages follow a pattern of filename, line number, message which is common to several tools. I used that in vi-like-emacs here.

Fairly recently (in 2014) gcc/g++ started adding a "calling-stack" to the messages, which gives the extra information. That relies upon a change to the preprocessor to track the line-numbers which can be turned off with a -P option (noted here), but that appears to be incompletely integrated in a form which would suppress the calling-stack.

Using clang would not help much with this; it can be very verbose as well. gcc/g++ development has added a lot of messages as noted here.

Solution 2

When compiling, errors are often accompanied by a lengthy trace (cyan). Is there a g++ flag to disable this, only showing the error itself?

  • You can use an old and no longer supported tool like STLFilt.

  • You can switch to Clang, or use it to report errors only and perform your final compilation in GNU g++.

  • You can become more familiar with STL which will make deciphering easier.

    A good understanding of the STL and how to use it will help you avoid lots of errors in the first place. Secondly, often error messages refer to functions in the STL source - if you have a rough idea how the STL is implemented, this can be extremely helpful in deciphering what the error message is going on about. The newest versions of the g++ compiler sometimes improve the output, making it more helpful and less verbose.

Not exactly what you want but it can shorten the output:

  • Use the -fmax-errors flag or -Wfatal-errors option:

    -fmax-errors=n

    Limits the maximum number of error messages to n, at which point GCC bails out rather than attempting to continue processing the source code. If n is 0 (the default), there is no limit on the number of error messages produced. If -Wfatal-errors is also specified, then -Wfatal-errors takes precedence over this option.

    -Wfatal-errors

    This option causes the compiler to abort compilation on the first error occurred rather than trying to keep going and printing further error messages.

Share:
9,821

Related videos on Youtube

Jack
Author by

Jack

Updated on September 18, 2022

Comments

  • Jack
    Jack almost 2 years

    When compiling, errors are often accompanied by a lengthy series of notes (cyan). Is there a g++ flag to disable this, only showing the error itself?

    • Admin
      Admin over 6 years
      What you are referring to is not a stack trace. stackoverflow.com/questions/45698710 Describe things properly, using the word note that is right in front of you, and people won't have to infer what you are even talking about by guessing your most probable colour scheme and working from there.
    • Admin
      Admin over 6 years
      Thank you! I edited the question to reflect that clarification.
    • Admin
      Admin over 4 years
    • Admin
      Admin over 2 years
      A lot of what I wanted to ignore were warnings, and I found I could do that with -w if that helps. I can focus on all related, error-only information this way.
  • Jack
    Jack over 6 years
    Thanks for this! The particularly long note sequences are with boost::asio actually. From similar questions, there does not seem to be an exact answer :-(