Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 968
Ann Brown Avatar asked Feb 17 '13 15:02

Ann Brown


2 Answers

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

like image 116
akid Avatar answered Oct 02 '22 19:10

akid


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

like image 37
Reza Toghraee Avatar answered Oct 02 '22 21:10

Reza Toghraee