rust-lang/cargo · error

`cargo run` can run at most one executable, but multiple…

Error message

`cargo run` can run at most one executable, but multiple were specified

What it means

Thrown by `cargo run` when a specific target filter (e.g. `--bin a --bin b` or `--example x --bin y`) selects more than one executable. `cargo run` can execute at most one binary, so multiple explicit selections are rejected even when the filter is specific.

Solutions

  1. Pass only a single `--bin` or `--example` flag to `cargo run`.
  2. If you need to build multiple targets, use `cargo build` instead.
  3. Review the available targets listed in the error message and pick one.

Example fix

# Before — multiple binaries
cargo run --bin app --bin cli

# After — single binary
cargo run --bin app
Defensive patterns

Strategy: validation

Validate before calling

// Validate that only one executable target is selected
fn count_selected_targets(bins: &[(&cargo::core::Package, &cargo::core::Target)]) -> usize {
    bins.len()
}
// Ensure this is exactly 1 before calling ops::run

Prevention

When it happens

Trigger: Running `cargo run` with multiple `--bin` flags, or a combination of `--bin` and `--example` flags that together match more than one runnable target. `bins.len() > 1` and `options.filter.is_specific()` is true.

Common situations: Passing `--bin foo --bin bar` to `cargo run`; using a filter that accidentally matches both a binary and an example; scripting `cargo run` with programmatically-built filters.

Related errors


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

Appendix: source

Thrown at src/ops/cargo_run.rs:87

                 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()
                )?;
            }
            anyhow::bail!(message)
        }
    }

    // `cargo run` is only compatible with one `--target` flag at most
    options.build_config.single_requested_kind()?;

    let compile = ops::compile(ws, options)?;
    assert_eq!(compile.binaries.len(), 1);
    let UnitOutput {
        unit,
        path,
        script_metas,
        env: _env,
    } = &compile.binaries[0];
    let exe = match path.strip_prefix(gctx.cwd()) {
        Ok(path) if path.file_name() == Some(path.as_os_str()) => Path::new(".").join(path),
        Ok(path) => path.to_path_buf(),
        Err(_) => path.to_path_buf(),

View on GitHub (pinned to eb98b54bc9)