【发布时间】:2019-12-17 22:33:35
【问题描述】:
我正在尝试设置 Visual Studio 代码以在 macOS 上使用 g++ 编译器构建/运行和调试 c++ 文件。但是,当我构建或调试代码时,我可以看到输出文件已创建并且我也可以运行它但是我无法在 vscode 中调试它,因为调试会产生奇怪的行为。
到目前为止,我已经能够编写构建 .cpp 文件并执行它的任务。输出进入 vscode 的终端。但是,当我尝试调试时,会打开一个新终端并且没有命中断点。
这里是tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Build with g++",
"type": "shell",
"command": "g++",
"args": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-std=c++11",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "run",
"type": "shell",
"command": "cd ${fileDirname}/ && ./${fileBasenameNoExtension}",
"dependsOn": ["Build with g++"]
}
]
}
这是我的 launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"showDisplayString": false,
"environment": [],
"externalConsole": true,
"internalConsoleOptions": "openOnSessionStart",
"MIMode": "lldb",
"logging": {
"moduleLoad": false,
"programOutput": true,
"trace": false
},
"preLaunchTask": "Build with g++",
"osx": {
"MIMode": "lldb"
}
}
]
}
我希望当我点击调试或按 f5 时,vscode 中的终端应该运行并且我能够调试程序。
【问题讨论】:
-
+1 因为我也很好奇这个问题的答案。我的 google-fu 让我失望了,尽管答案可能是一个指向“如何在 Mac 上/为 Mac 设置 VSC”网页的链接。
-
将
-g添加到您的构建命令中
标签: c++ macos visual-studio-code vscode-debugger vscode-tasks