VSCode只是一个编写代码的辅助工具,支持所有主流的开发语言,但是每一种语言的编译器,调试器是不一样的,而VSCode本身也不带这些编译调试工具。因此,想要在VSCode里开发调试程序,必须配套安装相应语言的编译工具。下面以C语言开发为例给大家介绍(具体操作可参考我的视频)
Task编译配置从Terminal>Configure Task...进入,需要将“command”指定为你电脑上minGW的路径;"Label"值根据自己喜好设定。
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "myGccTask",
"command": "E:\\Program files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
全局编译器路径设定
从左下角Manage>Setting>extensions>C/C , edit insetting.json
同样需要修改"C_Cpp.default.compilerPath"的路径。
{
"C_Cpp.updateChannel": "Insiders",
"cStandard": "c11",
"intelliSenseMode": "gcc-x64",
"C_Cpp.default.compilerPath": "E:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gcc.exe",
"C_Cpp.commentContinuationPatterns": [
"/**"
],
"git.autofetch": true,
"git.path": "E:\\Program Files\\Git\\bin\\git.exe",
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
}
调试功能配置
从Run>Open configurans进入,同样要修改“miDebuggerPath”的值。
注意:"preLaunchTask"的值要与Task中的“label”的值一致。
{
"version": "0.2.0",
"configurations": [
{
"name": "gcc my",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "E:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "myGccTask"
}
]
}
Git路径的配置
具体操作参见视频,参数参考本文02中“git.path”。