- task.json
{ "version": "2.0.0", "command": "g++", // label,可任取 "args": [ // g++命令行参数 "-g", "${workspaceFolder}\\*.cpp", "-I", "--std=c++11", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "problemMatcher": { "owner": "cpp", "fileLocation": [ "relative", "${workspaceFolder}" ], "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 } } }
- launch.json
{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示 "type": "cppdbg", // 配置类型,这里只能为cppdbg "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加) "program": "${fileDirname}/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径 "args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可 "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false "cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录 "environment": [], "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台 "MIMode": "gdb", "miDebuggerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应 "preLaunchTask": "g++", // 调试开始前执行的任务,要与task.json里的label/command值一样 "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": false } ] } ] }
- c_cpp_properties.json
{ "configurations": [ { "name": "Win32", "includePath": [ // 头文件包含路径 "${workspaceFolder}/**", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/include/**", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include" ], "defines": [ "_DEBUG", "UNICODE", "__GNUC__=6", "__cdecl=__attribute__((__cdecl__))" ], "intelliSenseMode": "msvc-x64", "browse": { "limitSymbolsToIncludedHeaders": true, "databaseFilename": "", "path": [ "${workspaceRoot}", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/include/**", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed", "C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include" ] } } ], "version": 4 }
- vscode预定义的变量
e.g.: 1. vscode编辑器打开的文件:/home/your-username/your-project/folder/file.ext 2. vscode打开的根工作区:/home/your-username/your-project ${workspaceFolder} - 在VS Code中打开的文件夹路径 - /home/your-username/your-project ${workspaceFolderBasename} - 在VS Code中打开的文件夹名称没有任何斜杠(/) - your-project ${file} - 当前打开的文件 - /home/your-username/your-project/folder/file.ext ${fileWorkspaceFolder} - 当前打开的文件所在的文件夹 - /home/your-username/your-project ${relativeFile} - 相对于workspaceFolder,当前打开的文件 - folder/file.ext ${relativeFileDirname} - 相对于workspaceFolder,当前打开的文件的目录名 - folder ${fileBasename} - 当前打开的文件的基名 - file.ext ${fileBasenameNoExtension} - 当前打开的文件的基名没有文件扩展名 - file ${fileDirname} - 当前打开文件的目录名 - /home/your-username/your-project/folder ${fileExtname} - 当前打开的文件的扩展名 - ext ${cwd} - 任务运行器启动时的当前工作目录 ${lineNumber} - 活动文件中当前选定的行号 ${selectedText} - 活动文件中当前选定的文本 ${execPath} - 运行VS Code可执行文件的路径 ${defaultBuildTask} - 默认生成任务的名称 ${pathSeparator} - 操作系统用于分隔文件路径中的组件的字符 - / on macOS or linux, \\ on Windows
参考: 1.官网:https://code.visualstudio.com/docs/cpp/config-mingw#_prerequisites 2.博客:https://blog.csdn.net/bat67/article/details/76095813