The simplest approach is to rebuild the program as a console application. The option to link.exe
needs to be /SUBSYSTEM:CONSOLE
instead of /SUBSYSTEM:WINDOWS
; presumably there is a straightforward way of specifying this in cmake.
This change shouldn't affect your GUI at all, but it will cause Windows to allocate a console if the process isn't already associated with one. Also, command line shells will usually wait for console applications to exit before continuing.
The other approach is to call AllocConsole
to explicitly create a new console, or AttachConsole
if you want to use an existing one. Or, of course, you could send the output to a log file.
Additional
Google 検索によると、ソース コードに次の行を追加することで、プログラムをコンソール アプリケーションとしてビルドできます。
#pragma comment(linker, "/SUBSYSTEM:CONSOLE")
これはおそらく最も簡単な解決策です。#if
デバッグビルド用のコンソールのみが必要な場合は、ブロックに入れることができます。
CMake: デバッグ ビルドに異なる ADD_EXECUTABLE を使用する方法も参照してください。