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

可紊 提交于 2019-12-18 10:47:45

问题


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 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.




回答2:


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.




回答3:


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

  • http://www.bdsoft.com/tools/stlfilt.html



回答4:


gccfilter does coloring & simplification of messages.

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




回答5:


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.




回答6:


check diagcc out, you can get something like this:

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




回答7:


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




回答8:


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



回答9:


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/



来源:https://stackoverflow.com/questions/656420/is-there-any-way-to-get-readable-gcc-error-and-warning-output-at-the-command-lin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!