Skip to content
Advertisement

How to set GCC_COLORS in gcc4.9 to emit colorizing diagnostics messages?

gcc4.9 supports the colorizing diagnostics for compiler warning/error messages.

We can enable it for a particular program using the option “fdiagnostics-color“. Currently I am using gcc4.9.1 and I append this particular option in my makefile as follows:

CC = /home/mantosh/gcc-4.9.1/bin/g++ -std=c++1y -Wall -pthread
DFLAG = -g -gdwarf-2 -fdiagnostics-color=always
OUTFILE = test

$(OUTFILE): test.cpp
    $(CC) $(DFLAG) -o $(OUTFILE) test.cpp

clean: 
    rm -f *.o $(OUTFILE)

If I compile a *.cpp file a get the following nice coloured message. This is really great feature added by GCC.

enter image description here

While reading the GCC offical link, it seems that this setting can permanently enabled using the GCC environmental variable “GCC_COLORS”.

Could somebody explains how to set/change/customize this particular environment variable?

I am using Ubuntu12.04/GCC4.9.1.

Advertisement

Answer

just add this line to your ~/.bashrc file:

export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

You can then reload it with source ~/.bashrc so you don’t have to logout/login.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement