/errors/cargo/a-bin-target-must-be-available
error: a bin target must be available for `cargo run`
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · cargo 1.98.1 (797e8a9bc 2026-08-05)updated
- tool
- Cargo
- exit code
- 101
- versions
- Rust 1.70+
- os
- any
error: a bin target must be available for cargo run means the package has no binary target: there is no src/main.rs, no file in src/bin/, and no [[bin]] section in Cargo.toml. This is normal for a library created with cargo new --lib. Add a src/main.rs with fn main(), run an example with cargo run --example NAME, or test the library with cargo test.
Reproduce it
cargo new --lib --vcs none -q mylib
cd mylib
cargo runOutput · exit 101
error: a bin target must be available for `cargo run`
Cargo exits with code 101, its code for any failed command.
Fix: add a binary next to the library
cargo new --lib --vcs none -q mylib
cd mylib
cat > src/main.rs <<'EOF'
fn main() {
println!("2 + 2 = {}", mylib::add(2, 2));
}
EOF
cargo run -qOutput
2 + 2 = 4
The library and the binary share the package: the binary imports the library by the package name (mylib::add).
The related error with several binaries
When the package has more than one binary and none is the default, cargo run cannot pick one:
cargo new --vcs none -q multi
cd multi
mkdir -p src/bin
echo 'fn main() { println!("tool"); }' > src/bin/tool.rs
cargo run -q
echo "--- with --bin"
cargo run -q --bin toolOutput
error: `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key. available binaries: multi, tool --- with --bin tool
Choose one with --bin NAME, or set a default in Cargo.toml:
[package]
name = "multi"
version = "0.1.0"
edition = "2024"
default-run = "multi"Where Cargo looks for binaries
| Location | Target |
|---|---|
| src/main.rs | Binary named after the package |
| src/bin/NAME.rs or src/bin/NAME/main.rs | Binary NAME |
| [[bin]] name = "x" path = "..." | Binary declared explicitly in Cargo.toml |
| examples/NAME.rs | Example, run with cargo run --example NAME |
Sources
Related pages
errors · cargoerror: could not find `Cargo.toml` in `...` or any parent directorycargo reports could not find Cargo.toml when run outside a Rust package. cd into the project, pass --manifest-path, or create a package with cargo new.cheat sheets · cargoCargo cheat sheet: build, run, test and manage Rust cratesCargo cheat sheet: new packages, check, build and run in debug or release, test, fmt, clippy, add and update dependencies, workspaces and flags for CI.flags · cargocargo build --release: optimised builds and target/releasecargo build --release uses the release profile (opt-level 3, no overflow checks) and writes to target/release. Debug vs release, and how to tune the profile.