25

For some long errors, the gcc output is dense and has lots of line-wrapping etc. Especially when errors are subtle, it can take me 10-30 seconds of squinting to parse it with my eyes.

I've taken to pasting this in an open code-editor window to get some basic syntax highlighting and enable reformatting with regex's.

Has anyone invented a more automated method?

  • 1
    I just make the window very wide... – i_am_jorf Mar 17 '09 at 23:33
  • 2
    Clarification: I love intel's c++ compiler. The messages are clean, short, and pointed. Back when I still had a license, I'd test my compiles in intel's compiler before I built with GCC just to find the big problems. – Robert P Mar 17 '09 at 23:45
  • @Robert I'm intrigued, hope I get a chance to try that sometime. Not appropriate on the current project unfortunately... – mph Mar 18 '09 at 04:28
  • My window was as wide and font as tiny as could be on my wide-aspect-ratio 21" screen, and when that was no longer enough, I came here ;) – mph Mar 18 '09 at 04:29
  • Only 10-30 seconds? It takes me longer than that just to scroll all the way to the top to see where the insanity begins! – Dronz Jul 08 '18 at 20:39
  • This is an old question and GCC now colorizes. – Yariv Nov 26 '19 at 12:23

9 Answers9

17

I use this script, called colorize:

#!/bin/bash
while read x ; do echo $x ; done \
| sed -e "s/.*error:.*/\x1b[1;36m&\x1b[0m/" \
-e "s/.*warning:.*/\x1b[1;36m&\x1b[0m/" \
-e "s/^\(.*\)\(required from\)/\x1b[1;36m\1\x1b[0mnote: \2/" \
-e "s/^\(.*\)\(In instantiation of\)/\x1b[1;36m\1\x1b[0mnote: \2/" \
-e "s/^\(.*\)\(In member\)/\x1b[1;36m\1\x1b[0mnote: \2/" \
| sed -e "s/error:/\x1b[1;31m&\x1b[1;36m/" \
-e "s/warning:/\x1b[1;35m&\x1b[1;36m/" \
-e "s/note:/\x1b[1;30m&\x1b[0m/"

Then I just call it like this(using make or whatever build system):

make |& colorize

And I get color output similar to clang.

Paul Fultz II
  • 17,682
  • 13
  • 62
  • 59
15

I've found colorgcc to be invaluable. By introducing coloring, it becomes much easier to mentally parse the text of gcc error messages, especially when templates are involved.

Mr Fooz
  • 109,094
  • 6
  • 73
  • 101
  • 1
    Hey, I posted that with a temp account and now I can't follow up with it, but I wanted to say thanks for this -- that is an awesome utility and just the sort I was looking for. – mph Mar 18 '09 at 04:24
  • I like this, but I would prefer message simplification like gccfilter and stlfilt does, although stlfilt doesn't do coloring – Dolan Antenucci Oct 05 '12 at 02:34
  • 1
    colorgcc is hackable. You might try modifying its source to run it through your favorite filtering program. – Mr Fooz Mar 19 '13 at 17:25
  • 2
    GCC trunk (which will be 4.9) supports colour diagnostics now – Jonathan Wakely Apr 22 '13 at 18:58
9

If your errors are template related, take a look at STLfilt:

Michael Burr
  • 333,147
  • 50
  • 533
  • 760
  • Michael, same story as comment to Mr. Fooz's answer above. Your answer was first and it was dead-on -- those template errors are exactly what inspired my post. I'll be using STLfilt from tomorrow until I die. BTW I voted both of you up using my new, functional account. Thanks again. – mph Mar 18 '09 at 04:26
  • FWIW, I find that there's no need for something like STLfilt with MS's newer compilers - they give quite readable error messages right out of the box now. – Michael Burr Mar 18 '09 at 06:03
  • This is nice, but I would prefer colorizing the output like colorgcc or gccfilter do. – Dolan Antenucci Oct 05 '12 at 02:35
7

gccfilter does coloring & simplification of messages.

http://www.mixtion.org/gccfilter/

migou
  • 71
  • 1
  • 1
  • I like that this one does coloring and message simplification, but it doesn't seem like I can symlink g++ to it (so that `make` will use it). Any suggestions? – Dolan Antenucci Oct 05 '12 at 02:33
  • dolan: create a symlink to a wrapper script inside "/usr/local/bin" (or other location that precedes the location of actual gcc in your $PATH) with something like: /path/to/your/gccfilter -c "/path/to/actual/gcc" "$@" – Maleev Feb 17 '13 at 05:10
  • 1
    @dolan: Here's another option if you're using a makefile: Define g++ as "CC=$(MY_CC_PREFIX) g++". Then, define MY_CC_PREFIX somewhere (inside the makefile or elsewhere) as "/path/to/gccfilter ". This allows you to easily change the arguments passed to gccfilter. Also, if MY_CC_PREFIX is not defined, you will just use g++ as expected. – Ryan Mar 25 '13 at 18:42
4

If you use GCC 4.9, you can add -fdiagnostics-color=auto as an additonal compilation flag. At some later version, the color has been enabled by default.

Martin Ueding
  • 8,245
  • 6
  • 46
  • 92
3

check diagcc out, you can get something like this:

colored message demo

If your gcc ≥ 4.9, you can use argument -fdiagnostics-color=always.

Martin Ueding
  • 8,245
  • 6
  • 46
  • 92
Tong Zhou
  • 566
  • 5
  • 7
2

To answer your question 4 years later, clang should be mentioned here.

ulidtko
  • 14,740
  • 10
  • 56
  • 88
0

Here's my current hack, which mostly inserts newlines and indentation in strategic locations along with a little extra annotation, but does nothing to address STL verbosity.

Note that as currently implemented, this script does not return an error if the compiler returned one, so doing something like this will not work properly: (make && ./runApplication). This could surely be remedied by someone with better bash-fu.

#!/bin/bash
# SUBSTITUTION RULES:
# Note: All substitution rules must end in a semi-colon, inside of the closing quote
subColonSpace='s/: /:\n /g;'
subSrc='s/^src/\nsrc/;'
subError='s/error:/error:\n\n======================================\nERROR:/;'
subWarning='s/ *error: *\n/ERROR: /;'
subWarning='s/ *warning: *\n/WARNING: /;'
subNote='s/note:/\n NOTE:/g;'
subOpenTic='s/‘/\n   ‘/g;'
subOpenParen='s/(/(\n      /g; s/(\n *)/()/g;'
subCommaSpace='s/, /,\n      /g;'

# Note: The order of these may matter
sedExpr="$subColonSpace $subSrc $subError $subWarning $subNote $subOpenTic      
$subOpenParen $subCommaSpace"

makelogFile=makelog.tmp

make "$@" 2>&1 | sed "$sedExpr" | tee $makelogFile
arr_sea
  • 841
  • 10
  • 16
0

if you like Ruby there is GilCC! GilCC is very easy to install (just copy it to the bin folder) and easy to use (just type GilCC instead of "gcc" or "make") and it works with GCC version. Unlike Perl based scripts GilCC has statistics such as # of warnings and error and compile time. You don't have to mess with .bash files and it is cross platform as long as you can run Ruby on your machine. Since it has the power of Ruby; you can make GilCC do different things such as trigger test automation, unit test or program external hardware after a successful build.

Here is the link to the download page: http://www.onlysolutionssoftware.com/gilcc/

Gilson
  • 1,708
  • 3
  • 16
  • 21