这篇文章主要说明Linux下VSCode配置C++工程,launch.json和tasks.json文件的修改方法.
使用默认设置生成这两个文件后,需要修的地方已经用注释进行了说明.
一共有4个地方需要修改.
- 编译生成的可执行文件;
- 任务名(两个文件中需要保持一致);
- 编译器设置;
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb)Linux",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main.out",//main.out后缀必须存在,否则主函数调用其他文件的函数会报错.main does not exit
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build", //这里要修改,需要和tasks.json中的 "label": "build",保持一致
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json文件
{
// 有关 tasks.json 格式的文档,请参见
// https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "build", //这里要修改,需要和launch.json中的 "preLaunchTask": "build",保持一致
"command": "g++", //这里要修改
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}