Cargo build where the executable file ./main?

Cargo build where the executable file ./main?

$ cargo new rust_projects --bin 

$ ls

Desktop  Documents  Downloads  Music  Pictures  Public  rust_projects  Templates  Videos
$ cd rust_projects/
$ ls

Cargo.toml  src
$ cd src

$ ls

main.rs

$ geany main.rs

$ cd -

/home/ukse/rust_projects

$ pwd
/home/ukse/rust_projects

$ cargo build

There is no main file “executable” in all project folder.

All build products (intermediate and final) are put into the hierarchy under the target directory. For debug (the default) builds, it’s target/debug.

If you use cargo run, it tells you which executable it is running.

1 Like

$ cargo build

and

$ cargo run

and i searched again and i did not find executable file.

Because you created a crate named “rust_projects”, the executable will be a file named “rust_projects”. cargo run will print out:

Running target/debug/rust_projects

2 Likes

@mbrubeck already told you where to find that specific executable, but if you are in doubt, you can always use find:

$ find target -maxdepth 2 -type f -executable
target/release/foo
target/debug/foo
1 Like