I want to debug a C++ project in VSCode (on a Mac, using either GDB or LLDB). The program itself takes command line arguments like
./prog -input cf file_x.txt
This works fine when starting a debugging session in GDB on the command line.
In VSCode, I tried to adapt launch.json
to read like this (only relevant lines shown):
"program": "${workspaceRoot}/build/prog",
"args": [
"-input cf",
"path_to/file_x.txt"
]
With this, I get @"Unknown option: \"-input cf\"\r\n"
in the output and the process is not debugged; alternatively, I tried only one argument like so:
"program": "${workspaceRoot}/build/prog",
"args": [
"-input cf path_to/file_x.txt"
]
resulting in the same message. Have I missed something important?
To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line. They will be passed to the program via the argv array.
To do that, open C++ file in VSCode and either hit F5 or go to Debug -> Start Debugging and select C++ (GDB/LLDB) then select g++.exe build and debug active file .
Download & Install the C/C++ Extension We need to click on the extension button that displays a sidebar for downloading and installing the C/C++ extension in the visual studio code. In the sidebar, type C Extension. In this image, click on the Install button to install the C/C++ extension.
Run and Debug C/C++ Code You’ll notice that there is also a .vscodefolder in your sample project. To configure debug configuration, 2 files are required launch.jsonand tasks.jsoninside .vscodefolder. VSCode can create and auto-configure these files if we try to debug for the first time.
And how we can start debugging or launch a code file by passing command line arguments. For this, you would need launch.json. If you have, just edit it as I will discuss in this post. To create a new launch.json, click on Run -> Open Configuratio or Run -> Add Configuration
In addition to debugging a program, VS Code supports running the program. The Debug: Run (Start Without Debugging) action is triggered with Ctrl+F5 and uses the currently selected launch configuration. Many of the launch configuration attributes are supported in 'Run' mode.
The program itself takes command line arguments like This works fine when starting a debugging session in GDB on the command line. In VSCode, I tried to adapt launch.json to read like this (only relevant lines shown):
Try it like this
"program": "${workspaceRoot}/build/prog",
"args": [
"-input",
"cf",
"path_to/file_x.txt"
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With