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

前端 未结 9 976
借酒劲吻你
借酒劲吻你 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 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
    

提交回复
热议问题