通过货物安装板条箱时出错:指定的包没有二进制文件

Error installing a crate via cargo: specified package has no binaries

我正在尝试使用 Cargo 在我的系统 (Arch Linux) 上安装一个 Rust crate。我可以搜索箱子并找到我需要的东西,例如:

 $ cargo search curl | head -n3
    Updating registry `https://github.com/rust-lang/crates.io-index`
curl (0.3.0)             Rust bindings to libcurl for making HTTP requests
curl-sys (0.2.0)         Native bindings to the libcurl library

当我尝试安装它时,出现以下错误:

 $ cargo install curl
    Updating registry `https://github.com/rust-lang/crates.io-index`
error: specified package has no binaries

这是什么意思?我必须先从源代码构建它吗?如果一开始不安装 Cargo 有什么意义?

 $ uname -a
Linux 4.6.1-2-ARCH #1 SMP PREEMPT Thu Jun 2 15:46:17 CEST 2016 x86_64 GNU/Linux
 $ rustc --version
rustc 1.9.0
 $ cargo --version
cargo 0.10.0 (10ddd7d 2016-04-08)

cargo install用于安装恰好通过crates.io分发的二进制包。

如果你想使用 crate 作为依赖项,请将它添加到你的 Cargo.toml

阅读 the Rust getting started guide and the Cargo getting started guide 了解更多信息。简而言之:

cargo new my_project
cd my_project
echo 'curl = "0.3.0"' >> Cargo.toml

有趣的是,您可以使用 cargo install 安装名为 cargo-edit 的第三方 Cargo 子命令,这样可以更轻松地修改 Cargo.toml 文件以添加依赖项!

cargo install cargo-edit
cargo add curl

需要注意的重要一点是每个 Cargo 项目管理和编译一组单独的依赖项(some background info)。因此,安装 compiled 库没有意义。每个版本库的源代码将缓存在本地,避免多次下载。

另请参阅: