簡體   English   中英

清單中沒有指定目標 - 必須存在 src/lib.rs、src/main.rs、[lib] 部分或 [[bin]] 部分

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

我正在按照“Rust 編程語言”一書中的說明構建猜謎游戲,但每當我嘗試在 VSCodium(VSCode 的開源版本)終端中運行我的代碼(通過命令Cargo run )時,我的代碼由於以下錯誤而拒絕運行:

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

這是我的 Cargo.toml 文件的樣子:

[package]
name = "GuessingGame"
path = "src/GuessingGame.rs"
version = "0.1.0"
edition = "2021"
authors = ["my name <example@example.com>"]

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

[dependencies]

版本:VSCodium:1.73.1 操作系統:Zorin OS 16.2

我嘗試將[package]更改為[[bin]][lib] ,但它給了我更多錯誤,即: this virtual manifest specifies a [lib] section, which is not allowed的並且this virtual manifest specifies a [[bin]] section, which is not allowed

要獲得所需的配置,您需要分別指定 package目標。

[package]
name = "GuessingGame"
version = "0.1.0"
edition = "2021"

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


[dependencies]

也就是說——請不要覆蓋路徑。 Rust 項目在堅持標准項目布局時更具可讀性,這是由 Cargo 自動檢測到的。

為此,請將源文件命名為src/main.rs而不是src/GuessingGame.rs ,並完全從Cargo.toml中省略[[bin]]部分和path 構建的可執行文件仍將自動命名為GuessingGame ,因為這是您的 package 名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM