'Rust not printing to terminal
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?
Solution 1:[1]
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.
Solution 2:[2]
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.
Solution 3:[3]
On Linux and Mac:
rustrc helloworld.rs && ./helloworld
Solution 4:[4]
You can simply use:
cargo run
This will compile current project and run it just with one command.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Lymphatus |
Solution 2 | kaveh |
Solution 3 | Juliano |
Solution 4 | Developer |