构建工程
Terminal > Configure Default Build Task
提示选择你的编译器,之后自动生成类似如下代码
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": ["-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
debug工程
Run > Add Configuration....
自动创建一个空的launch.json
拷贝下面的到这个launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ 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": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
该博客详细介绍了如何在Visual Studio Code中配置C++的编译和调试环境。首先,通过Configure Default Build Task设置编译器,生成了用于编译当前活动文件的g++任务。接着,创建了launch.json文件,定义了一个名为'g++buildanddebugactivefile'的调试配置,该配置会调用预设的编译任务并在调试模式下运行程序。整个过程确保了从构建到调试的一站式体验。

6146

被折叠的 条评论
为什么被折叠?



