How to compile rust programm with no console?

In python using pyinstaller I can add command-line argument "--noconsole" or "-w" and as a result I can get executable file that runs without appearing console. So, how I can get the same in rust? What I should to do?

Assuming you run windows, try checking the "windows_subsystem" attribute.
(just put the referred setting as a first line of your main.rs file)

4 Likes

and how will this help me? There is not even a hint of compilation without a console

I interpreted above as that you want your complied program executable to run without console window appearing, which is exactly what the linked setting does (e.g. for GUI apps).

I may have misunderstood what you mean, in which case someone else can possibly jump in :slight_smile:

1 Like

From the link by @RustyJoeM above:

The "windows" subsystem is commonly used by GUI applications that do not want to display a console window on startup. It will run detached from any existing console.

#![windows_subsystem = "windows"]
3 Likes

okay, but how to do this with linux programs?

AFAIK, this does not apply to linux applications. When you start your program via a desktop entry, your program is never attached to a terminal. If you start your program from the terminal and wish to detach it from it, see i.e. this superuser question: linux - How do I detach a process from Terminal, entirely? - Super User

2 Likes

If you just want to not have output when running cargo in a terminal, try cargo build --release --quiet. If that's not quiet enough for you, you can redirect all output to /dev/null. In most shells, something like

cargo build --release >/dev/null 2>/dev/null

The redirection is a general shell/unix capability, not a Rust or Cargo specific thing.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.