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?

2
  • These are target properties and not variables. See this answer: https://stackoverflow.com/a/52654220/487892 Commented Feb 17, 2022 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 Commented Feb 17, 2022 at 16:45

0

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.