[Rust报错]error: `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key

1 minute read Published: 2020-12-21

cargo无法确定要运行哪一个二进制文件, 可以使用--bin指定一个二进制文件, 或者在cargo.toml中加一个default-run的key.

cargo run --bin project_name_or_binary_name

or

[package]
name = "hello"
version = "0.1.0"
authors = ["Floyda <floyda@163.com>"]
edition = "2018"
default-run="hello" # 默认运行哪个二进制文件

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[[bin]]
name="foo"
path="src/foo.rs"

参考链接

stackoverflow
doc.rust-lang.org