1
[package]
name = "my package"
version = "0.1.0"
authors = ["me"]
edition = "2018"

[dependencies]
nalgebra = "0.18.1"

我试图用上面的 Cargo.toml 编译 rust,但它给了我以下错误:

error: expected item, found `[`
 --> Cargo.toml:1:1
  |
1 | [package]
  | ^ expected item

error: aborting due to previous error

如果我删除nalgebra = "0.18.1",我可以解决这个问题,但我不能使用nalgebra包,所以它对我没有帮助。

4

2 回答 2

2

我认为您的 Cargo.toml 存在多个问题

这是不允许的:

name = "my package"

建议:

name = "my-package"

还有缺失的部分:

error during execution of `cargo metadata`: error: failed to parse manifest at `test/Cargo.toml`

Caused by:
  no targets specified in the manifest
  either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present

你能把整个文件贴在这里吗?

最小可行设置:

[package]
name = "my-package"
version = "0.1.0"
authors = ["me"]
edition = "2018"

[[bin]]
name = "radkilla"
path = "src/main.rs"
doc = false

[dependencies]
nalgebra = "0.18.1"

src/main.rs

fn main() {}

运行 fmt 并构建:

➜  test cargo fmt ; cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
于 2019-10-03T14:49:15.553 回答
1

关闭在 Visual Studio 上打开的 cargo.toml 文件后,错误消失。

于 2019-10-03T14:55:41.283 回答