[Solved] Console window still opens when using #![windows_subsystem(windows)]


#1

Part of the 1.18 release notes said:

For our Windows users, Rust 1.18.0 has a new attribute, #![windows_subsystem].

When is this useful? In the simplest terms, if you’re developing a graphical application, and do not specify windows, a console window would flash up upon your application’s start. With this flag, it won’t.

If I compile this simple example and double click on the .exe file in Windows Explorer:

#![windows_subsystem(windows)]

use std::{thread, time};

fn main() {
    let ten_millis = time::Duration::from_secs(3);
    thread::sleep(ten_millis);
}

A console window pops up for 3 seconds and then goes away. I thought that the attribute made it so the console window wasn’t suppose to appear? What am I missing?

Config

  • Windows 10 x64
> rustup show
...
active toolchain
----------------

stable-x86_64-pc-windows-msvc (default)
rustc 1.18.0 (03fc9d622 2017-06-06)

#2

The blog is wrong – it should be #![windows_subsystem = "windows"].

It’s weird, even invalid entries like #![windows_subsystem(cuviper)] are accepted and ignored.


#3

That did it, thanks!

Should I:

  1. report a bug about the silent failure (seems like there should at the very least be a warning) and
  2. report the incorrect information about the blog (where would I do that?)

#4

Yeah, I think both 1 and 2 are appropriate. Here’s the blog repo.


#5