简体   繁体   English

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

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

I'm trying to install a Rust crate on my system (Arch Linux) using Cargo.我正在尝试使用 Cargo 在我的系统(Arch Linux)上安装 Rust crate。 I can search for crates and find what I need, for example:我可以搜索板条箱并找到我需要的东西,例如:

 $ 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

When I try to install it, I get the following error:当我尝试安装它时,出现以下错误:

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

What does this mean?这是什么意思? Do I have to build it from source first?我必须先从源代码构建它吗? What's the point of Cargo if it does not install it in the first place?如果 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 is used to install binary packages that happen to be distributed through crates.io. cargo install用于安装碰巧通过 crates.io 分发的二进制包。

If you want to use a crate as a dependency, add it to your Cargo.toml .如果您想使用 crate 作为依赖项,请将其添加到您的Cargo.toml

Read the Rust getting started guide and the Cargo getting started guide for further information.阅读Rust 入门指南Cargo 入门指南以获取更多信息。 In short:简而言之:

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

Amusingly, you can install a third-party Cargo subcommand called cargo-edit using cargo install that makes it easier to modify your Cargo.toml file to add dependencies!有趣的是,您可以使用cargo install安装一个名为cargo-edit的第三方Cargo 子命令,这样可以更轻松地修改您的Cargo.toml文件以添加依赖项!

cargo install cargo-edit
cargo add curl

An important thing to note is that every Cargo project manages and compiles a separate set of dependencies ( some background info ).需要注意的重要一点是,每个Cargo 项目都管理和编译一组单独的依赖项(一些背景信息)。 Thus it doesn't make sense to install a compiled library.因此安装编译库是没有意义的。 The source code for each version of a library will be cached locally, avoiding downloading it multiple times.库的每个版本的源代码都将缓存在本地,避免多次下载。

See also:另见:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM