Skip to content

/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

bash
cargo new --lib --vcs none -q mylib
cd mylib
cargo run

Output · 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

bash
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 -q

Output

2 + 2 = 4

The library and the binary share the package: the binary imports the library by the package name (mylib::add).

When the package has more than one binary and none is the default, cargo run cannot pick one:

bash
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 tool

Output

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:

Cargo.toml
[package]
name = "multi"
version = "0.1.0"
edition = "2024"
default-run = "multi"

Where Cargo looks for binaries

LocationTarget
src/main.rsBinary named after the package
src/bin/NAME.rs or src/bin/NAME/main.rsBinary NAME
[[bin]] name = "x" path = "..."Binary declared explicitly in Cargo.toml
examples/NAME.rsExample, run with cargo run --example NAME

Sources