rust-lang/cargo · error · anyhow::Error

`cargo run` could not determine which binary to run. Use the

Error message

`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: {}

What it means

When no specific target is selected and the package exposes more than one [[bin]], `cargo run` cannot pick one, so cargo_run.rs:66 bails and lists the available binaries, suggesting --bin or the default-run manifest key.

Source

Thrown at src/ops/cargo_run.rs:66

    if bins.len() == 1 {
        let target = bins[0].1;
        if let TargetKind::ExampleLib(..) = target.kind() {
            anyhow::bail!(
                "example target `{}` is a library and cannot be executed",
                target.name()
            )
        }
    }

    if bins.len() > 1 {
        if !options.filter.is_specific() {
            let mut names: Vec<&str> = bins
                .into_iter()
                .map(|(_pkg, target)| target.name())
                .collect();
            names.sort();
            anyhow::bail!(
                "`cargo run` could not determine which binary to run. \
                 Use the `--bin` option to specify a binary, \
                 or the `default-run` manifest key.\n\
                 available binaries: {}",
                names.join(", ")
            )
        } else {
            let mut message = "`cargo run` can run at most one executable, but \
                 multiple were specified"
                .to_owned();
            write!(&mut message, "\nhelp: available targets:")?;
            for (pkg, bin) in &bins {
                write!(
                    &mut message,
                    "\n    {} `{}` in package `{}`",
                    bin.kind().description(),
                    bin.name(),
                    pkg.name()

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Specify the binary explicitly: `cargo run --bin <name>`.
  2. Set a default in Cargo.toml: `[package] default-run = "<name>"` so bare `cargo run` works.
  3. Use `cargo run -p <pkg> --bin <name>` if you are outside the package directory.

Example fix

# before
$ cargo run
error: `cargo run` could not determine which binary to run.
available binaries: cli, daemon

# after (option A - flag)
$ cargo run --bin cli

# after (option B - manifest default)
[package]
name = "my-crate"
default-run = "cli"
Defensive patterns

Strategy: validation

Validate before calling

# Count bin targets; require a default or an explicit --bin:
bins=$(cargo read-manifest 2>/dev/null \
  | jq '[.targets[]|select(.kind|index("bin"))]|length')
def=$(grep -qE '^default-run' Cargo.toml && echo yes || echo no)
if [ "$bins" -gt 1 ] && [ "$def" = no ] && ! echo "$*" | grep -q -- '--bin'; then
  echo "ambiguous; pass --bin <name> or set default-run" >&2; exit 1
fi
cargo run "$@"

Prevention

When it happens

Trigger: Running `cargo run` in a package with two or more [[bin]] targets and no `default-run` set in [package].

Common situations: CLI + daemon binaries in one crate; adding a second binary without configuring a default; workspace member with multiple bins.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/efb68472cc1856b0.json. Report an issue: GitHub.