Visual Studio 2017 has built-in support for cmake projects, meaning you can just open a folder containing a CMakeLists.txt and use it. However, there doesn't seem to be a way to prevent the console window from closing after running an executable.
With a normal Visual Studio project, you can use Ctrl+F5 to run without the debugger attached. However, Ctrl+F5 did exactly the same thing as F5, that is, it ran the executable and closed the console window immediately.
Another suggestion was to set the subsystem to "console" for the application, but the cmake project has no Visual Studio project that I can set settings for.
I figured maybe I could go to the Debug and Launch Settings for my CMakeLists.txt (right click > Debug and Launch Settings > target.exe), which opened launch.vs.json. Unfortunately, I was unable to find documentation on this. By looking through the schema, though, it seemed as if I could set "noDebug": true
, but this just turned off the debugger and did nothing to stop the console from closing:
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "target.exe",
"name": "target.exe",
"noDebug": true
}
]
}
This is driving my crazy. I can't just add a system("pause")
to the main function, as I'm using a main function provided by a test framework. Furthermore, that should be completely unnecessary; Visual Studio should handle it for me.
How can I make the Visual Studio console not close after my executable finished, when my executable is from a cmake project?
I'm using Microsoft Visual Studio Community 2017, Version 15.2 (26430.16) Release