I’m having trouble getting a simple exe to run… outside of Visual Studio. (I have looked at previously posted questions that are phrased similarly but turn out to be more complex situations involving missing libraries.)
In MS Visual Studio 2022 I can add a new Console project to my "Solution".
I leave the default "Hello World" sample code as is.
Within Visual Studio, I can run the program with debug mode chosen and pressing either the solid green or hollow green buttons… a console window will be spawned with the appropriate program output displayed inside it.
Still within Visual Studio, I can run the program with release mode chosen and pressing either the solid green or hollow green buttons… a console window will be spawned with the appropriate program output displayed inside it.
In release mode, a .exe is created in the x64/release folder designated for such things.
Double clicking on the .exe has no effect. No console window is spawned.
If i merely "Build" the project in Visual Studio, that also creates a .exe file.
However that result also will not run if double-clicked on.
Here is typical VS output from the build. No errors are noted.
1>------ Build started: Project: ConsoleApplication2, Configuration: Release x64 ------
1>Generating code
1>0 of 11 functions ( 0.0%) were compiled, the rest were copied from previous compilation.
1> 0 functions were new in current compilation
1> 0 functions had inline decision re-evaluated but remain unchanged
1>Finished generating code
1>ConsoleApplication2.vcxproj -> E:_BI_ProjectsCplusPlus_take5x64ReleaseConsoleApplication2.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 6:34 PM and took 00.229 seconds ==========
What needs to be done to create a working EXE in this simple default situation?
2
Answers
Since you created a console application, you must run it from a command window to see the result.
If you click on the executable in File Explorer, then the console window opens, the program output is written to it, and the window closes immediately. "Hello, world" program runs too fast for you to notice the window appearing for a fraction of a second.
If you launch a console application from Window Explorer, rather than running it from a console window, then the console window used by your program will be closed as soon as your program ends. It can happen so fast, that you don’t get a chance to see the program’s output, before the window closes.
A simple fix is to add some input at the end of your program, so that the console window will be held open, while input is pending.
For example:
Something like this will allow you to run your program by double-clicking the
.exe
name in Windows Explorer, without opening a console window first.