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

前端 未结 9 971
借酒劲吻你
借酒劲吻你 2020-12-23 21:58

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 wi

相关标签:
9条回答
  • 2020-12-23 21:59

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

    • http://www.bdsoft.com/tools/stlfilt.html
    0 讨论(0)
  • 2020-12-23 22:01

    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
    
    0 讨论(0)
  • 2020-12-23 22:04

    gccfilter does coloring & simplification of messages.

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

    0 讨论(0)
  • 2020-12-23 22:06

    check diagcc out, you can get something like this:

    colored message demo

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

    0 讨论(0)
  • 2020-12-23 22:08

    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.

    0 讨论(0)
  • 2020-12-23 22:12

    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.

    0 讨论(0)
提交回复
热议问题