installation - 通过 cargo : specified package has no binaries 安装箱子时出错

标签 installation rust rust-cargo rust-crates

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

 $ 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 分发的二进制包。

如果你想使用一个箱子作为依赖,将它添加到你的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 子命令使用 cargo install 可以更轻松地修改 Cargo.toml 文件以添加和删除依赖项!

cargo install cargo-edit
cargo add curl
cargo rm curl

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

另见:

关于installation - 通过 cargo : specified package has no binaries 安装箱子时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37706999/

相关文章:

error-handling - 如何处理 Read::read_to_end 方法的错误?

rust - "thread ' <main> ' has overflowed its stack"构造大树时

rust - 无法构建Dotenv V0.15.0-使用rust 的 cargo

rust-cargo - cargo 安装 : specify a/tmp substitute?

rust - 构建 trpl-ebook 时遇到错误 : patterns aren't allowed in methods without bodies

xcode - Pandas 在 Mac 上安装错误

installation - 运行 RemovePreviousVersion 时,MSI 不会安装所有文件

windows - Anaconda python3.5 windows gdal安装

java - 使用java 1.6安装Jenkins

function - 在函数内部定义结构是对其他函数隐藏结构的好方法吗?