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

前端 未结 9 970
借酒劲吻你
借酒劲吻你 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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.

提交回复
热议问题