Rust not printing to terminal

Viewed 1614

rustc is not outputting anything to terminal when using println!.

Code:

fn main() {
   println!("Hello, world!");
}

Running it:

me@mclaptop:~
> rustc helloworld.rs

me@mclaptop:~
>

Why does it not print anything?

4 Answers

rustc is the compiler of the Rust language, it just produces an executable to be run. If you want to actually see the output you must run the ./helloworld command.

You can read about it here.

rustc only compiles your code. You need to call the output binary to get it working.

Try ./helloworld or whatever the name of the output file is.

On Linux and Mac:

rustrc helloworld.rs && ./helloworld

You can simply use:

cargo run

This will compile current project and run it just with one command.

Related