【问题标题】:Rust: Cargo.toml error: expected item, found `[`, when trying to include nalgebraRust:Cargo.toml 错误:预期项目,在尝试包含 nalgebra 时发现 `[`
【发布时间】:2019-10-23 21:39:14
【问题描述】:
[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 包,所以它对我没有帮助。

【问题讨论】:

  • 看起来您(或您的 IDE)错误地运行了 rustc Cargo.toml 而不是 cargo run 或其他什么。 (expected item, found ... 是一个 rustc 错误。)

标签: rust rust-cargo


【解决方案1】:

我认为您的 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

【讨论】:

  • 如果您有 src/main.rs 文件,则不需要 [[bin]] 部分 - Cargo 会自动提取该部分。
【解决方案2】:

关闭在visual studio中打开的cargo.toml文件后错误消失。

【讨论】:

  • 可能与Cargo.lock 锁定Cargo.toml 有关?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
  • 2011-02-19
  • 1970-01-01
相关资源
最近更新 更多