I’m trying understand the interaction between the C/C++ extension, Code Runner, and the VS Code buttons to build, run, and debug my C++ code. I’m running MacOS Sonoma 14.4.1 and my VS Code details are listed at the end.
I have added a task of type cppBuild
to tasks.json. For the menu items in the image below (available in the editor pane when editing any C++ file) I get the following behavior:
Debug C/C++ File
: This respects my task definition and I believe that, should I define another task, I can use the “gear” to configure this menu item to use it. It will launch the debugger and I can step through code. All good.
Run Code
: This invokes g++ Algorithm.cpp -o Algorithm
which is not how my task is defined (I have many other compiler options selected).
Run C/C++ File
: This uses my task to build and runs my binary but I’d like to configure a command line argument and it’s not clear to me where to add this.
Next is the green play button in the “Run and Debug” view pictured in the image below.
I have defined a configuration of type cppdbg
in launch.json. If I edit the name I can see it change in the drop down and if I add another configuration it will appear in the drop down. However, when I press play I get an error:
Unable to start debugging. Launch options string provided by the project system is invalid. Unable to determine path to debugger. Please specify the “MIDebuggerPath” option.
I did try to add the requested option but it seems that lldb
doesn’t except the -mi
option.
My configuration is as follows:
"name": "Launch (lldb)",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false
I do not have gdb
installed but do have lldb
:
$ /usr/bin/lldb --version
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Version: 1.88.1
Commit: e170252f762678dec6ca2cc69aba1570769a5d39
Date: 2024-04-10T17:42:52.765Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Darwin x64 23.4.0