No Console Output To Terminal on Windows When Using CMake
-
QT6.4 Windows 10:
I have a console application that runs in a terminal and emits log messages via qDebug(). These messages appear as expected in the terminal when the project is built with qmake but do not appear when the project is built with CMake.
If the CMake-built executable is run with "Run in terminal" unchecked in the Projects->Run wizard, then qDebug() messages appear correctly in the QtCreator Application Output pane. If the "Run in terminal" is checked, no output appears in either the Application Output pane or the terminal.
Is there a CMake variable that needs to be set in order to enable terminal output in a CMake console app on Windows?
Thanks.
-
QT6.4 Windows 10:
I have a console application that runs in a terminal and emits log messages via qDebug(). These messages appear as expected in the terminal when the project is built with qmake but do not appear when the project is built with CMake.
If the CMake-built executable is run with "Run in terminal" unchecked in the Projects->Run wizard, then qDebug() messages appear correctly in the QtCreator Application Output pane. If the "Run in terminal" is checked, no output appears in either the Application Output pane or the terminal.
Is there a CMake variable that needs to be set in order to enable terminal output in a CMake console app on Windows?
Thanks.
@KenAppleby-0 said in No Console Output To Terminal on Windows When Using CMake:
Is there a CMake variable that needs to be set in order to enable terminal output in a CMake console app on Windows?
Yes, see WIN32 keyword for add_executable()
-
@KenAppleby-0 said in No Console Output To Terminal on Windows When Using CMake:
Is there a CMake variable that needs to be set in order to enable terminal output in a CMake console app on Windows?
Yes, see WIN32 keyword for add_executable()
Thanks. But I find that adding WIN32 to add_executable (or qt_add_executable) makes no difference.
The doc you linked to says:
"If WIN32 is given the property WIN32_EXECUTABLE will be set on the target created."This prompted me to look at the Qt-generated entry in the CMakeLists.txt file:
set_target_properties(application PROPERTIES WIN32_EXECUTABLE ON MACOSX_BUNDLE ON )
So the WIN32_EXECUTABLE is already set...
But, removing the WIN32_EXECUTABLE ON line, or changing it to WIN32_EXECUTABLE OFF fixes the problem. Debug output appears in the terminal.
This fits, I think, with the CMake documentation for WIN32_EXECUTABLE: "When this property is set to true the executable when linked on Windows will be created with a WinMain() entry point instead of just main(). This makes it a GUI executable instead of a console application."So the answer seems to be to not have either WIN32 in the add_executable or WIN32_EXECUTABLE ON in the set_target_properties?
-
Thanks. But I find that adding WIN32 to add_executable (or qt_add_executable) makes no difference.
The doc you linked to says:
"If WIN32 is given the property WIN32_EXECUTABLE will be set on the target created."This prompted me to look at the Qt-generated entry in the CMakeLists.txt file:
set_target_properties(application PROPERTIES WIN32_EXECUTABLE ON MACOSX_BUNDLE ON )
So the WIN32_EXECUTABLE is already set...
But, removing the WIN32_EXECUTABLE ON line, or changing it to WIN32_EXECUTABLE OFF fixes the problem. Debug output appears in the terminal.
This fits, I think, with the CMake documentation for WIN32_EXECUTABLE: "When this property is set to true the executable when linked on Windows will be created with a WinMain() entry point instead of just main(). This makes it a GUI executable instead of a console application."So the answer seems to be to not have either WIN32 in the add_executable or WIN32_EXECUTABLE ON in the set_target_properties?
@KenAppleby-0 said in No Console Output To Terminal on Windows When Using CMake:
So the answer seems to be to not have either WIN32 in the add_executable or WIN32_EXECUTABLE ON in the set_target_properties?
Yes - as the documentation states WIN32 creates an application with WinMain() as entry point and therefore has no console.