Compiling a Graphical application in windows without command prompt

So far the only way, which is very hacky I've got the command prompt to disappear is to use the code on stackoverflow (which i can't seem to link to, as i'm a new user).

I'm wondering if anyone can explain how to link with -mwindows to make the application Graphical only

You can do it by adding -C link-args=-mwindows to your compile arguments.

If you're using Cargo... well, you're kinda out of luck. You can use cargo rustc and pass the flag every time you compile, but beyond that, I can't find any way to add arbitrary flags to the build commands. This is because Cargo knows better than you and there's obviously no reason for you to ever want to set a linker flag manually. :stuck_out_tongue:

Yeah this is the problem, I need to do it via Cargo, I tried to see if i can do that via cargo rustc subcommand, but alas it doesn't like it, thanks for the help anyway

Make sure you include the extra -- between cargo options and rustc options.

Cheers! Using cargo rustc -- -C link-args=-mwindows

Does get it to compile, anyone got any ideas, though, why it crashes immediately when running though?

I've found it only happens when calling println!

Well, there's not much point in printing to stdout if that isn't connected to anything. Still Rust shouldn't crash (or probably panic) in this case.

Using println! should no longer crash in Rust 1.2 since that RFC was implemented. Just get the latest beta or nightly.

1 Like

Probably a bit late, but for those still landing here when looking into this issue:

https://stackoverflow.com/questions/29763647/how-to-make-a-program-that-does-not-display-the-console-window/29764309#29764309

=> since rust 1.18 : #![windows_subsystem = "windows"]

no need for linker annoyances. yay