這篇文章主要說明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"
}
]
}