Is there any way to get readable gcc error and warning output at the command line?

mikeh picture mikeh · Mar 18, 2009 · Viewed 12.9k times · Source

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?

Answer

Paul Fultz II picture Paul Fultz II · Mar 15, 2013

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.