Answer#
Windows marks every program with a subsystem. A console program gets a console window (or shares the one it was started from). A GUI program gets none. Rust builds console programs by default, so a double-clicked GUI app also opens a black window.
One line at the top of the crate root changes that:
// Release builds on Windows get the GUI subsystem (no console window); debug builds keep the console for println!.
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
println!("hello"); // visible only when the console exists
}cfg_attr(condition, attribute) applies the attribute only when the condition holds, here "not a debug build". On macOS and Linux the windows_subsystem attribute has no effect, so the line is harmless there.
What was checked: both builds were made, run, and the Subsystem field in the PE header of each executable was read. The debug build has value 3 (console) and printed hello; the release build has value 2 (GUI) and printed nothing.
Side effects of the GUI subsystem:
println!output goes nowhere, and panics print no message anywhere a user can see it. Log to a file in the app's data folder (see the settings thread), and show a message box or error banner for fatal errors.- A program started from a terminal does not print into that terminal. Windows offers a way to attach to the parent's console (
AttachConsolein the Windows API); it needs a call into the Windows API. - Command-line tools that share the code should be a separate binary in the same package, built as a console program.
Common mistakes#
- Applying
windows_subsystemto a debug build and then wondering whyprintln!and panic messages vanish. Thecfg_attrline above avoids it. - Putting the attribute in a module. It belongs at the crate root (the top of
main.rs) and needs the#!form. - Using it for a service or a tool that must print: they need the console subsystem.
Related questions#
Does it also set the icon or version information?#
No. Those are resources embedded in the executable; a build.rs with a resource crate does it. This thread covers only the console window.
Sources#
- The Rust Reference,
windows_subsystemattribute: https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute (read 2026-12-05) - The Rust Reference,
cfg_attr: https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute (read 2026-12-05)