gcc-fdiagnostics颜色是否适用于Windows



我使用的是Windows 7,在mintty(Cygwin)和Windows命令提示符终端中,我没有得到任何颜色的MinGW GCC错误消息。

$ 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

对于这两个终端,当我使用git命令时,我可以看到颜色,所以终端本身就很好。我可以在Ubuntu Linux(GCC 4.9)中使用相同的GCC命令,而不需要GCC_COLORS环境变量,并且着色确实有效。

我的MinGW GCC 5.2来源于https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/dongsheng-每日/,可能是gcc-5-win32(稳定)。

gcc -v给出:

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)

我看到这张关于这个问题的票被关闭了,因为它对某人有效。https://sourceforge.net/p/mingw-w64/feature-requests/66/

如何使错误着色工作

(我确实尝试了gcc-5-win64,它也有同样的问题……而且clang -fcolor-diagnostics也失败了,Clang 3.7.1来源于:http://llvm.org/releases/download.html#3.7.1)

在gcc 6.3.0的diagnostic-color.c的源代码中出现:

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

然后是真正的逻辑。要解决此问题,如果您自己构建gcc,请将第一行更改为#if 0。这对我很有效,使用MSYS2作为外壳在mingw-w64 5.2.0(32位)下构建了gcc-6.3.0。

如果你使用的是预打包的gcc构建,我想你已经被卡住了。


一个gcc错误已被提交,回应称(转述)"当前gcc开发人员中没有人使用Windows,要解决此问题,使用Windows的人需要通过补丁提交过程"。

在错误报告线程上,链接了一个第三方补丁,它试图使用Win32系统调用来检测shell功能来实现auto行为。

使用我上面的解决方案,"自动"行为默认为"关闭",您必须使用"始终"开关来启用它(这对我来说很好,但我想对其他人来说可能不好)。

最新更新