rust-lang/cargo · error

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

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

Thrown by `cargo run` when multiple binary targets exist in the selected package(s) and no specific target selection (`--bin` or `default-run`) narrows it to one. The error message lists all available binary names to help the user choose.

Solutions

  1. Specify the binary explicitly: `cargo run --bin <name>`.
  2. Set `default-run = "<name>"` in the `[package]` section of Cargo.toml.
  3. Remove the extra binary targets if only one is intended.

Example fix

# Cargo.toml — set a default binary
[package]
name = "my_crate"
default-run = "my_app"

# Or specify on the command line
cargo run --bin my_app
Defensive patterns

Strategy: validation

Validate before calling

fn count_binaries(pkg: &cargo::core::Package) -> usize {
    pkg.manifest().targets().iter().filter(|t| t.is_bin()).count()
}
// If > 1, prompt user to set default-run or use --bin

Prevention

When it happens

Trigger: Running `cargo run` (without `--bin`) on a package that has two or more `[bin]` targets (e.g. `src/main.rs` plus files in `src/bin/`). `bins.len() > 1` and no specific filter is set.

Common situations: A multi-binary CLI crate; adding a second binary via `src/bin/` without setting `default-run`; workspace with multiple default binaries.

Related errors


AI-assisted analysis of rust-lang/cargo@eb98b54bc9 (2026-08-11). Data as JSON: /api/errors/efb68472cc1856b0. Report an issue: GitHub.

Appendix: 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 eb98b54bc9)