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

问题描述 投票:23回答:1

我正在尝试使用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)
installation rust rust-cargo rust-crates
1个回答
42
投票

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

如果要将crate用作依赖项,请将其添加到Cargo.toml

阅读the Rust getting started guidethe Cargo getting started guide以获取更多信息。简而言之:

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

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

cargo install cargo-edit
cargo add curl

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

© www.soinside.com 2019 - 2024. All rights reserved.