20

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?

2 Answers 2

31

Try it like this

"program": "${workspaceRoot}/build/prog",
            "args": [
              "-input",
              "cf",
              "path_to/file_x.txt"
            ]
Sign up to request clarification or add additional context in comments.

1 Comment

I know this is old but this page will be updated with changes. code.visualstudio.com/docs/cpp/launch-json-reference#_args
1

In 2022, I just do :

 "args": [
    "your_arg1",
    "your_arg2"
 ]

(in launch.json of course)

3 Comments

This is already said in the accepted answer, please avoid duplicating information
I was looking up how to this exact thing and found this page. The answer adds "-input". This is not needed in 2022, hence my answer.
if that is the case, then you should've commented on the original answer instead

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.