MacOS vscode配置c++(cpp)debug功能
在.vscode文件夹下两个重要的文件为tasks.json
和launch.json
,
launch中是debug的配置调用了一些tasks里的任务,tasks中定义任务.
点击右边的小虫子就能DEBUG了
"program"中的内容可能会不一致,因为在编译的时候生成的名字不同。我这个就是生成不带后缀的可执行文件。
怎么传入参数呢,只能用外部终端了"externalConsole": true,
,集成终端不会搞cry
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "C/C++: g++ 生成活动文件"//这个可以在点击调试的时候自动编译一次你的代码(省事)
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ 生成活动文件",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: /usr/bin/g++"
}
]
}