{"record":{"id":"efb68472cc1856b0","repo":"rust-lang/cargo","slug":"cargo-run-could-not-determine-which-binary-to-ru","errorCode":null,"errorMessage":"`cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key.\navailable binaries: {}","messagePattern":"`cargo run` could not determine which binary to run\\. Use the `--bin` option to specify a binary, or the `default-run` manifest key\\.\navailable binaries: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_run.rs","lineNumber":66,"sourceCode":"\n    if bins.len() == 1 {\n        let target = bins[0].1;\n        if let TargetKind::ExampleLib(..) = target.kind() {\n            anyhow::bail!(\n                \"example target `{}` is a library and cannot be executed\",\n                target.name()\n            )\n        }\n    }\n\n    if bins.len() > 1 {\n        if !options.filter.is_specific() {\n            let mut names: Vec<&str> = bins\n                .into_iter()\n                .map(|(_pkg, target)| target.name())\n                .collect();\n            names.sort();\n            anyhow::bail!(\n                \"`cargo run` could not determine which binary to run. \\\n                 Use the `--bin` option to specify a binary, \\\n                 or the `default-run` manifest key.\\n\\\n                 available binaries: {}\",\n                names.join(\", \")\n            )\n        } else {\n            let mut message = \"`cargo run` can run at most one executable, but \\\n                 multiple were specified\"\n                .to_owned();\n            write!(&mut message, \"\\nhelp: available targets:\")?;\n            for (pkg, bin) in &bins {\n                write!(\n                    &mut message,\n                    \"\\n    {} `{}` in package `{}`\",\n                    bin.kind().description(),\n                    bin.name(),\n                    pkg.name()","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/ops/cargo_run.rs#L48-L84","documentation":"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.","triggerScenarios":"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.","commonSituations":"A multi-binary CLI crate; adding a second binary via `src/bin/` without setting `default-run`; workspace with multiple default binaries.","solutions":["Specify the binary explicitly: `cargo run --bin <name>`.","Set `default-run = \"<name>\"` in the `[package]` section of Cargo.toml.","Remove the extra binary targets if only one is intended."],"exampleFix":"# Cargo.toml — set a default binary\n[package]\nname = \"my_crate\"\ndefault-run = \"my_app\"\n\n# Or specify on the command line\ncargo run --bin my_app","handlingStrategy":"validation","validationCode":"fn count_binaries(pkg: &cargo::core::Package) -> usize {\n    pkg.manifest().targets().iter().filter(|t| t.is_bin()).count()\n}\n// If > 1, prompt user to set default-run or use --bin","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set `default-run` in `[package]` when a crate has multiple binaries.","Always use `--bin <name>` when running in multi-binary crates.","Document the primary binary in your crate's README."],"tags":["cargo-run","ambiguous","multiple-binaries","target-selection"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}