Visual Studio 2017 has built-in support for cmake projects, that is, you can simply open the folder containing CMakeLists.txt and use it. However, there seems to be no way to prevent the console window from closing after running the executable .
With a normal Visual Studio project, you can use Ctrl + F5 to run without an attached debugger. However, Ctrl + F5 did the same as F5 , that is, it ran an executable file and immediately closed the console window.
Another suggestion was to configure the subsystem to be a “console” for the application, but the cmake project does not have a Visual Studio project that I can set for parameters.
I thought maybe I can go to the Debug and Launch settings for my CMakeLists.txt (right click> "Debug and Launch Settings"> target.exe) that launched launch.vs. JSON Unfortunately, I could not find any documentation about this. However, looking at the diagram, it seemed that I could set "noDebug": true , but it just turned off the debugger and did nothing to stop the console:
{ "version": "0.2.1", "defaults": {}, "configurations": [ { "type": "default", "project": "CMakeLists.txt", "projectTarget": "target.exe", "name": "target.exe", "noDebug": true } ] }
It drives me crazy. I can’t just add system("pause") to the main function, since I am using the main function provided by the test environment. Moreover, this should be completely unnecessary; Visual Studio should handle it for me.
How can I make the Visual Studio console close after the completion of my executable file when my executable file is executed from the cmake project?
I am using Microsoft Visual Studio Community 2017, version 15.2 (26430.16) Release