0

I have set up a cmake project using visual studio 2019. I want to start the debug session with some command line parameters.

To achieve that, I've configured the CMakeLists.txt with the VS_DEBUGGER_COMMAND_ARGUMENTS:

set( VS_DEBUGGER_COMMAND_ARGUMENTS "this" "is" "a" "test" ) 
set( VS_DEBUGGER_WORKING_DIRECTORY "." )

The first thing my C++ code do is to print out that parameters:

if (argc > 1) {
    // config_file = argv[1];
    for (std::size_t i = 0; i < argc; i++) {
        std::cout << "argument " << i << ": " << argv[i] << std::endl;
    }
}
else {
    std::cout << "the value of argc is: " << argc << std::endl;
}

The problem is that when I run Debug, the output I've always see is the value of argc is 1. I've also tried to modify the launch.vs.json file as appears in this related question:

Adding command line arguments to project

and it doesn't work. Any ideas?

Raul Luna
  • 1,945
  • 1
  • 17
  • 26
  • These are target properties and not variables. See this answer: [https://stackoverflow.com/a/52654220/487892](https://stackoverflow.com/a/52654220/487892) – drescherjm Feb 17 '22 at 12:17
  • I've just done that and keeps on failing. The cmake compiles, and executes, but it seems to ignore these properties. I've selected minimum version for cmake the 3.13 – Raul Luna Feb 17 '22 at 16:45

0 Answers0