我一直在嘗試.cpp在 vscode 中除錯檔案,并且以下檔案已完美安裝。(我已經.cpp通過運行檔案,code-runner extension但現在我想除錯 c 檔案。)
$ clang --version // or g --version (both same result)
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
我點擊了除錯按鈕并嘗試了列出的每個編譯器
C/C : clang build and debug active fileC/C : clang build and debug active fileC/C : g build and debug active fileC/C : cpp build and debug active file
但是在每次嘗試中,我都遇到了以下結果:
Build finished successfully.
* Terminal will be reused by tasks, press any key to close it.
或錯誤訊息
The preLaunchTask 'C/C : g build active file' terminated with exit code -1.
還有另一種方法可以在 macOS 上的 vscode 中除錯 c 檔案嗎?
我的tasks.json檔案(我的c 檔案在專案根目錄下)
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C : clang build active file",
"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": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
我的launch.json檔案
{
"configurations": [
{
"name": "C/C : clang build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C : clang build active file"
}
],
"version": "2.0.0"
}
uj5u.com熱心網友回復:
launch.json "preLaunchTask": "C/C : clang build active file"
使用 task.json "label": "C/C : clang build active file" 因為它是執行任務
所以你launch.json應該被修改
通知變化clang to clang 匹配任務標簽
{
"configurations": [
{
"name": "C/C : clang build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C : clang build active file"
}
],
"version": "2.0.0"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/510566.html
上一篇:nxbuild命令因TypeError失敗:無法讀取未定義的屬性(讀取“云”)
下一篇:迭代紅寶石中的回圈?
