{"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":"validation","errorClass":"anyhow::Error","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/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_run.rs#L48-L84","documentation":"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.","triggerScenarios":"Running `cargo run` in a package with two or more [[bin]] targets and no `default-run` set in [package].","commonSituations":"CLI + daemon binaries in one crate; adding a second binary without configuring a default; workspace member with multiple bins.","solutions":["Specify the binary explicitly: `cargo run --bin <name>`.","Set a default in Cargo.toml: `[package] default-run = \"<name>\"` so bare `cargo run` works.","Use `cargo run -p <pkg> --bin <name>` if you are outside the package directory."],"exampleFix":"# before\n$ cargo run\nerror: `cargo run` could not determine which binary to run.\navailable binaries: cli, daemon\n\n# after (option A - flag)\n$ cargo run --bin cli\n\n# after (option B - manifest default)\n[package]\nname = \"my-crate\"\ndefault-run = \"cli\"","handlingStrategy":"validation","validationCode":"# Count bin targets; require a default or an explicit --bin:\nbins=$(cargo read-manifest 2>/dev/null \\\n  | jq '[.targets[]|select(.kind|index(\"bin\"))]|length')\ndef=$(grep -qE '^default-run' Cargo.toml && echo yes || echo no)\nif [ \"$bins\" -gt 1 ] && [ \"$def\" = no ] && ! echo \"$*\" | grep -q -- '--bin'; then\n  echo \"ambiguous; pass --bin <name> or set default-run\" >&2; exit 1\nfi\ncargo run \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set `default-run` in [package] for crates with multiple binaries.","Always pass `--bin <name>` when more than one binary exists.","Keep the primary binary in src/main.rs so auto-detection is predictable."],"tags":["run","targets","ambiguity","binary","manifest"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}