【问题标题】:cargo would not build even when src/main.rs is available即使 src/main.rs 可用, cargo 也不会构建
【发布时间】:2020-04-10 06:19:19
【问题描述】:

我正在尝试使用 cargo build 进行构建。以下是项目结构

tree
.
├── Cargo.toml
└── src
    └── main.rs

Cargo.toml 的内容

[package]
name = "server"
version = "0.1.0"
authors = ["Lokanath Mohanty <lokanath.mohanty@adcolony.com>"]
edition = "2018"

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

[dependencies]

src/main.rs的内容

use std::io::{ErrorKind, Read, Write};
use std::net::TcpListener;
use std::sync::mpsc;
use std::thread;
use std::time::Duration;

const LOCAL_IP: &str = "127.0.0.1:6001";
const MSG_SIZE: usize = 32;


fn main() {
    ...
}

我收到以下错误 -

error: failed to parse manifest at `/home/debashishc/Downloads/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

【问题讨论】:

  • Are you sure ? 提示 "/home/debashishc/Downloads/Cargo.toml"
  • 我不明白你的意思。我上传的代码是正确的。
  • - - 给ls /home/debashishc/Downloads/src/main.rs的命令是什么?
  • 该文件不存在。但我正在从目录“/home/debashishc/Downloads/Rust/server”运行命令。这个目录确实有一个 Cargo.toml。为什么要在 /home/debashishc/Downloads 中寻找 Cargo.toml ?

标签: rust rust-cargo


【解决方案1】:

Cargo 寻找并尝试parse Cargo.toml in parent directories,因为它会检查您的箱子是否是更大的workspace 的一部分。

从父目录中删除损坏的Cargo.toml。或者,将您的 crate 的 Cargo.toml 设为工作区,以阻止货物进一步搜索。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    • 2019-12-19
    • 2011-08-22
    • 2019-11-26
    • 1970-01-01
    • 2018-12-17
    相关资源
    最近更新 更多