exe",
], // 编译命令参数
"type": "shell", // 可以为shell或process,前者相当于先打开shell再输入命令,后者是直接运行命令
"group": {
"kind": "build",
"isDefault": true // 设为false可做到一个tasks.json配置多个编译指令,需要自己修改本文件,我这里不多提
},
"problemMatcher":{
"owner": "$gcc",
"fileLocation":"absolute",
"pattern":[
{
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
//"location": 2,
"message": 5
}
]
}
}
]
}
Linux
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json
{
// 有关 tasks.json 格式的文档,请参见
// https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-l",
"pthread"
?
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
]
}
]
}
配置说明
一般情况下,c++的debug过程是这样的,首先vscode调用launch.json, launch.json根据"preLaunchTask": "gcc build active file",
的名称调用名为"gcc build active file"
的task.json, task.json中可以有多个task,根据tasks中的label名调用对应的任务。task主要负责进行编译成可执行文件。如果仅仅需要生成可执行文件,直接按crtl+shift+b
即可。
c_cpp_properties主要是针对c/c++编译进行的专门配置,如include路径等。
强烈建议看json中的英文,其描述是非常容易理解的。对c++的编译过程、对Linux稍微有些基础的人都能够快速掌握并进行私人定制。
详细的vscode配置参见微软。强烈推荐看微软的docs说明,虽然看起来读着费时间,但是远远要比你上网搜索各种资料更加快速。因为即使你按照我的配置设置成功了,当应用于不同的工程或者语言时,很可能难以进行配置。