I am using gcc 4.9.2 with ccache 3.1.10. My shell environment contains GCC_COLORS=auto
(from here; tried yes
and always
too).
As a minimal test I compile this main.c
file
int main() {
int a;
return 0;
}
with gcc -c main.c -Wall -o main.o
and observe (as desired)
main.c: In function ‘main’:
main.c:2:7: warning: unused variable ‘a’ [-Wunused-variable]
int a;
^
with main.c:
and main.c:2:7:
, ‘main’:
and ‘a’
in bold face, the ^
in boldface green, and the warning:
in magenta bold face.
Compiling with ccache
the colorisation disappears.
NB: ccache gcc -Wall -c main.c -o main.o
is colorless, but ccache gcc -Wall main.c -o main
remains colored.
NB2: ccache gcc -Wall -c main.c -o main.o -fdiagnostics-color
also preserves colors in the output.
Question: Is there a recommended way to have the export GCC_COLORS
functionality with ccache
? I'd prefer to have colors globally enabled (as through the ~/.MYSHELLrc
) and without adding -fdiagnostics-color
globally to $CFLAGS
[0] and I want to avoid custom wrappers which parse the output messages (and might get confused with LC_MESSAGES
settings).
[0]: I have many Makefiles
which don't add their config to CFLAGS
but overwrite the environment settings.
Not really sure it's relevant anymore, but I just tested with
GCC_COLORS=yes
with ccache version 3.4.1 and gcc 7.4.0 and that seems to work fine for me. I had the same issue whenGCC_COLORS
wasn't set.