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

30,144

Solution 1

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

Solution 2

Gcc 4.9 seems to have added this feature via the -fdiagnostics-color flag:

Solution 3

Debian and Ubuntu gives the colorgcc package for that purpose.

And I usually run gcc (and make) thru emacs with M-x compile then the messages are colorized.

addenda

GCC 4.9 has a native colorization facility and GCC 6 - released end of April 2016 - (and probably GCC 5 too) is enabling it by default (when stdout is a terminal).

Solution 4

Ok, I'll just leave a notice about my own (python based) tool also :)

It is called Pluggable Output Processor and designed not only to colorize output of one particular program. Here is sample GCC output before:

Pluggable Output Processor Before After: Pluggable Output Processor Before

Solution 5

See colorgcc, a perl script that coulours the gcc output.

Share:
30,144
Ann Brown
Author by

Ann Brown

Updated on July 09, 2022

Comments

  • Ann Brown
    Ann Brown almost 2 years

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