Jetski S-type
Jetski S-type

Reputation: 1208

Is gcc -fdiagnostics-colour working on Windows?

I am using Windows 7, and in both the mintty (Cygwin) and Windows Command Prompt terminals, I don't get any colour for MinGW GCC error messages.

$ printenv GCC_COLORS
error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01
$ gcc -c -fdiagnostics-color=always file.cpp -o file.o

For both terminals, I can see colour when I use git commands, so the terminals are fine themselves. I can use the same GCC command in Ubuntu Linux (GCC 4.9) without the GCC_COLORS environment variable, and the colouring does work.

I sourced my MinGW GCC 5.2 from https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/dongsheng-daily/, probably the gcc-5-win32 (stable).

gcc -v gives:

Target: i686-w64-mingw32
Configured with: /home/drangon/work/mingw-w64-dgn_32/source/gcc-5.2.0/configure --host=i686-w64-mingw32 --target=i686-w64-mingw32 --disable-nls --enable-languages=c,c++,objc,obj-c++ --with-gmp=/home/drangon/work/mingw-w64-dgn_32/build/for_target --with-mpfr=/home/drangon/work/mingw-w64-dgn_32/build/for_target --with-mpc=/home/drangon/work/mingw-w64-dgn_32/build/for_target --with-isl=/home/drangon/work/mingw-w64-dgn_32/build/for_target --enable-twoprocess --disable-libstdcxx-pch --disable-win32-registry --prefix=/home/drangon/work/mingw-w64-dgn_32/target --with-sysroot=/home/drangon/work/mingw-w64-dgn_32/target
Thread model: win32
gcc version 5.2.0 (GCC)

I saw this ticket about this very issue was closed because it was working for someone. https://sourceforge.net/p/mingw-w64/feature-requests/66/

How do I get the error colouring working?

(I did try the gcc-5-win64, which has the same issue... and also clang -fcolor-diagnostics fails, with Clang 3.7.1 sourced from: http://llvm.org/releases/download.html#3.7.1)

Upvotes: 4

Views: 3167

Answers (1)

M.M
M.M

Reputation: 141648

In the source code for gcc 6.3.0's diagnostic-color.c there appears:

#if (defined _WIN32)
bool
colorize_init (diagnostic_color_rule_t)
{
  return false;
}
#else

followed by the real logic. To fix this, if you're building gcc yourself, change the first line to #if 0. This worked for me, building gcc-6.3.0 under mingw-w64 5.2.0 (32-bit) using MSYS2 as a shell.

If you're using a pre-packaged build of gcc I guess you're stuck.


A gcc bug has been filed with the response that (paraphrased) "nobody among the current gcc developers is using Windows, and to fix this, someone using Windows needs to go through the patch submission process".

On the bug report thread, there is a third party patch linked which attempts to implement the auto behaviour using Win32 system calls to detect shell capability.

Using my solution above, the "auto" behaviour defaults to "off" and you have to enable it with the "always" switch (which is perfectly fine to me, but I guess might not be fine to others).

Upvotes: 3

Related Questions