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

情到浓时终转凉″ 提交于 2019-12-12 16:14:49

问题


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.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/26070873/how-to-set-gcc-colors-in-gcc4-9-to-emit-colorizing-diagnostics-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!