[英]How to get debugging c++ to work in VSCode on a mac?
下载C / C ++扩展后,可以使用配置在VsCode的调试窗口中生成project.json。 如果您当前在项目的.vscode文件夹下没有project.json,请点击F5并显示一个下拉列表。 在那里你可以选择C ++(GDB / LLDB),这应该生成一个project.json供你使用。
如果你想点击F5以便它自动编译和调试你的程序,你需要添加一个tasks.json。 这可以通过点击F1并选择Tasks: Configure Task Runner
并选择Other
。 将“echo”替换为“gcc”(或clang)并将args替换为.cpp文件,并且不要忘记添加-g。
您可以在其文档中找到更多信息: https : //code.visualstudio.com/docs/languages/cpp
我不计算我失去的时间寻找这个问题的答案!
我找到了vscode-lldb扩展,它工作正常,我找到的所有其他解决方案对我不起作用。
你仍然需要创建配置文件,这是我的调试我的单元测试:
我在这个例子中使用googletest和扩展名c ++ 14
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build & debug tests",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-std=c++14",
"-I/src",
"-lgtest",
"tests/MainTest.cpp",
"-o",
"bin/testMain"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}
launch.json
{
"version": "0.2.0",
"configurations":
[
{
"name": "Debug Tests C/C++",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/bin/testMain",
"args": [],
"cwd": "${workspaceFolder}/tests",
"preLaunchTask": "build & debug tests"
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.