俺的了解十分肤浅。俺没啥文化, 初中毕业,大伙都知道。
但是 GCC 给俺的记忆十分深刻, 就是错误或者警告提示可以有彩色的。
######################################################################
老实说, 俺也是在自己的另一台电脑上注意到有这个玩法。
还花了一个晚上阅读 VS CODE 的说明。
时间就是这样浪费掉的。
但是, 没找到任何有用的提示。
今天终于在寻找 GCC 的编译开关时发现了这个诀窍。
分享给大家。
"-fdiagnostics-color=always"
-fdiagnostics-color=always 俺菜鸟, 所以也用上这个 "-Wall", "-Wextra",
当然, 很可能许多人知道, 但俺是第一次了解。
"-fdiagnostics-color=always" 俺菜鸟, 所以也用上这个 "-Wall", "-Wextra",
TASKS.JSON
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc build active file", "command": "/usr/lib64/ccache/gcc", "args": [ "-lm", "-lpthread", "-lasound", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}", "`pkg-config", "--cflags", "gtk+-3.0`", "`pkg-config", "--libs", "gtk+-3.0`", "-fdiagnostics-color=always" ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "new", "showReuseMessage": true, "clear": false } }, { "type": "shell", "label": "run", "command": "/usr/lib64/ccache/gcc", // "args": [ "-lm", "-lpthread", "-lasound", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}", "`pkg-config", "--cflags", "gtk+-3.0`", "`pkg-config", "--libs", "gtk+-3.0`", "-fdiagnostics-color=always" // 彩色警告在这里弄 ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "test", "isDefault": true }, "presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "new", "showReuseMessage": true, "clear": false } } ], "version": "2.0.0" }
*** 备注: WINDOWS 下 GCC 也有这个效果
//////////////////////////////////////////////////////////////////////
#####################################################################################################################################
TASKS.JSON (GCC WINDOWS)
{ "version": "2.0.0", "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe build active file", "command": "C:\MinGW\bin\gcc.exe", "args": [ "-lm", "-g", "${file}", "-o", "${fileDirname}\${fileBasenameNoExtension}.exe", "-fdiagnostics-color=always" ], "options": { "cwd": "C:\MinGW\bin" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "compiler: C:\MinGW\bin\gcc.exe" }, { "type": "shell", "label": "C/C++: gcc.exe build active file", "command": "C:\MinGW\bin\gcc.exe", "args": [ "-lm", "-g", "${file}", "-o", "${fileDirname}\${fileBasenameNoExtension}.exe", "-fdiagnostics-color=always" ], "options": { "cwd": "C:\MinGW\bin" }, "problemMatcher": [ "$gcc" ], "group": "build", "detail": "compiler: C:\MinGW\bin\gcc.exe" } ] }
LAUNCH.JSON (WINDOWS)
*** 备注: 可能有错误, 但是能正常跑 HELLO WORLD
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "MY TESTING LAUNCH", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "C:\MinGW\bin", "environment": [], "MIMode": "gdb", "miDebuggerPath": "C:\MinGW\bin\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: gcc.exe build active file" } ] }
c_cpp_properties.json (WINDOWS)
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "C:\MinGW\include" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "windowsSdkVersion": "10.0.18362.0", "compilerPath": "C:\MinGW\bin\gcc.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "windows-gcc-x86" } ], "version": 4 }
##########################################################################
##########################################################################
另一台 WINDOWS 电脑上的配置文件 (能跑 HELLO WORLD)
TASKS.JSON
{ "version": "2.0.0", "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe build active file", "command": "C:\msys64\mingw64\bin\gcc.exe", "args": [ "-lm", "-g", "${file}", "-o", "${fileDirname}\${fileBasenameNoExtension}.exe", //"`pkg-config", "--cflags", "gtk+-3.0`", "`pkg-config", "--libs", "gtk+-3.0`", //"$(pkg-config --cflags gtk+-3.0)", "-Wall", "-Wextra", "-fdiagnostics-color=always" ], "options": { "cwd": "C:\msys64\mingw64\bin" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "compiler: C:\msys64\mingw64\bin\gcc.exe" }, { "type": "shell", "label": "C/C++: gcc.exe build active file", "command": "C:\msys64\mingw64\bin\gcc.exe", "args": [ "-lm", "-g", "${file}", "-o", "${fileDirname}\${fileBasenameNoExtension}.exe", //"`pkg-config", "--cflags", "gtk+-3.0`", "`pkg-config", "--libs", "gtk+-3.0`", //"$(pkg-config --cflags gtk+-3.0)", "-Wall", "-Wextra", "-fdiagnostics-color=always" ], "options": { "cwd": "C:\msys64\mingw64\bin" }, "problemMatcher": [ "$gcc" ], "group": "build", "detail": "compiler: C:\msys64\mingw64\bin\gcc.exe" } ] }
LAUNCH.JSON (WINDOWS)
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "MY TESTING LAUNCH", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "C:\msys64\mingw64\bin", "environment": [], "MIMode": "gdb", "miDebuggerPath": "C:\msys64\mingw64\bin\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: gcc.exe build active file" } ] }
c_cpp_properties.json (WINDOWS)
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "C:\msys64\mingw64\include", "C:\msys64\mingw64\lib\glib-2.0\include", "C:\msys64\mingw64\include\gtk-3.0", "C:\msys64\mingw64\include\glib-2.0", "C:\msys64\mingw64\include\pango-1.0", "C:\msys64\mingw64\include\harfbuzz", "C:\msys64\mingw64\include\freetype2", "C:\msys64\mingw64\include\libpng16", "C:\msys64\mingw64\include\libpkgconf", "C:\msys64\mingw64\include\fribidi", "C:\msys64\mingw64\include\libxml2", "C:\msys64\mingw64\include\cairo", "C:\msys64\mingw64\include\pixman-1", "C:\msys64\mingw64\include\gdk-pixbuf-2.0", "C:\msys64\mingw64\include\gio-win32-2.0", "C:\msys64\mingw64\include\atk-1.0", "C:\msys64\mingw64\include\libgladeui-2.0" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "windowsSdkVersion": "10.0.18362.0", "compilerPath": "C:\msys64\mingw64\bin\gcc.exe", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "windows-gcc-x86" } ], "version": 4 }
不用谢。
这个问题透着一股邪乎味儿,怎么看怎么危险啊……
建议专业机构给予支援。