简体   繁体   中英

In VSCode, unable to use args in launch.json to pass command-line arguments to C++ project using cmake

I am using VSCode to debug a C++ project configured and built using CMake tools (extension in VScode).

I have to use below command to trigger the execution: ./cbs_ta -i ifile.yaml -o ofile.yaml

As you can see, there are two command line inputs (-i and file name for input file) (-o and file name for output file). I read that using "args" parameter in launch.json, we can pass command line arguments. So I modified "args" in launch.json as follows: "args": ["-i", "ifile_1.yaml", "-o", "ofile_1.yaml"],

Unfortunately, I am getting error that the option '--input' is required but missing

I used CMake Tools extension to configure and build the targets.

Please help.

Edit: I have identified that when I click "debug" menu option in CMake in VSCode, the debug session starts but it does not take into consideration launch.json . I identified it since I kept ```"stopAtEntry": true''' but it did not stop at entry point.

It sounds like you have encountered the confusing 'extra' debug button which the CMake Tools extension places on the toolbar. The C/C++ extension's main debugger, configured via 'launch.json', needs to be invoked using the 'debug' view in the left side panel (as do other debug extensions such as cortex-debug).

Once a debug configuration has been selected, a debug launch button is added to the status bar. This means that users of the CMake Tools extension will then have two different debug buttons on the status bar, which is confusing to say the least. Presumably in part because of this confusion, the CMake Tools extension has options which can be placed in 'settings.json' to remove the buttons it adds to the status bar, either selectively or all together. This is also a useful way to recover quite a bit of status bar real estate, if you don't often need to use things like the toolchain selector.

To remove all buttons added by CMake Tools:

    "cmake.statusbar.visibility": "hidden"

And to selectively remove the debug launch button:

    "cmake.statusbar.advanced": {
        "debug": {
            "visibility": "hidden"
        }
    }

I would expect most users to prefer the selective option, as things like the build target selector are fairly essential to most use cases.

The underlying issue here is that for some reason the CMake Tools extension does not use the standard extension point for debugging functionality, but instead just places an extra button on the status bar to invoke debugging directly without a configuration entry in 'launch.json'. The CMake Tools extension docs describe this as a 'quick' debug function, which suggests that their reason for this design decision is related to different use cases, although personally I can't really see a clear use case for it. Debugging is by its nature an activity which is highly dependent on configuration, as everything from the choice of actual debug program on down needs to be specified in most cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM