gccg++ansi-colors

Is there an easy way to COLOR-CODE the compiler outputs?


gcc (or other compilers) often generate huge text output and it's very difficult to see where the error is or miss warnings. I've done some search but havn't found a clean simple solution to color code the compiler output (so for instance warnings are yellow, errors are red, etc...)


Solution

  • here's an alternative if you are looking for something very simple:

    #!/bin/bash -e
    
    make ${@} 2>&1 | perl -wln -M'Term::ANSIColor' -e '
    m/Building|gcc|g++|\bCC\b|\bcc\b/ and print "\e[1;32m", "$_", "\e[0m"
    or
    m/Error/i and print "\e[1;91m", "$_", "\e[0m"
    or
    m/Warning/i and print "\e[1;93m", "$_", "\e[0m"
    or
    m/Linking|\.a\b/ and print "\e[1;36m", "$_", "\e[0m"
    or
    print; '
    

    Just alias your make to this script and make sure it's executable...