Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does rustc not run my simple "hello world" program?

Tags:

rust

I just set up Rust according to the doc and created my first program.

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

I saved it as main.rs and kicked off using:

[root@localhost hello_world] rustc main.rs
[root@localhost hello_world] 

But no output ever appears. Running rustc --version does show the version number, so considering the install went without problem, I am wondering where the problem is.

like image 288
robue-a7119895 Avatar asked Dec 26 '22 02:12

robue-a7119895


1 Answers

Rust is a compiled language. rustc is the compiler, which takes a source file and produces a binary which can then be executed; it does not itself execute the code, however. You must take the binary it produces (by default, the source filename minus the .rs extension) and execute it yourself with ./main or similar.

If you use Cargo, there is cargo run which compiles the code if necessary and then runs it.

like image 108
Chris Morgan Avatar answered Dec 31 '22 01:12

Chris Morgan