为了让它发挥作用,我已经筋疲力尽了。我的tasks.json是
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/opt/homebrew/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /opt/homebrew/bin/g++"
}
]
}
我的 launch.json 是
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"cwd": "${workspaceFolder}",
"MIMode": "lldb"
}
]
}
但是当我点击 Visual Studio Code 底部的 bug 进行调试时,收到错误消息
无法开始调试。项目系统提供的启动选项字符串无效。无法确定调试器的路径。 请指定“MIDebuggerPath”选项。
我该怎么办?
我花了很长时间询问聊天gpt并在谷歌上搜索答案。
在运行调试之前必须先生成可执行文件,并且还应该从 launch.json 启动此任务。
示例:
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ compilar archivo activo",
"command": "/usr/bin/clang++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compilador: /usr/bin/clang++"
}
]
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) M1 Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang++ compilar archivo activo"
}
]
}
其中program是编译main.cpp的可执行输出。
记住运行任务并在代码文件聚焦时启动。