Search code examples
gccerror-messaging

How to make gcc print errors/messages in short format (without citations from source)


When I compile my source, gcc generates messages in following format:

apue.h:97:17: note: ‘#pragma message: _POSIX_ADVISORY_INFO = 200809L’
   97 |         #pragma message "_POSIX_ADVISORY_INFO = " XSTR(_POSIX_ADVISORY_INFO)
      |                 ^~~~~~~
apue.h:100:17: note: ‘#pragma message: _POSIX_CPUTIME = 0’
  100 |         #pragma message "_POSIX_CPUTIME = " XSTR(_POSIX_CPUTIME)
      |                 ^~~~~~~
...

But I want gcc to generate messages in following format:

apue.h:97:17: note: ‘#pragma message: _POSIX_ADVISORY_INFO = 200809L’
apue.h:100:17: note: ‘#pragma message: _POSIX_CPUTIME = 0’
...

Which option can do that?


Solution

  • If you want to have the source citations omitted only for #pragma message then you cannot do this with a commandline option. You would need to pipe the build log through an external filter.

    If you are content for source citations to be omitted for all diagnostics, then use the option -fno-diagnostics-show-caret. See the GCC Manual: 3.7 Options to Control Diagnostic Messages Formatting