通过货物安装周转箱时出错:指定的软件包没有二进制文件 [英] Error installing a crate via cargo: specified package has no binaries
问题描述
我正在尝试使用Cargo在我的系统(Arch Linux)上安装Rust板条箱.我可以搜索箱子并找到所需的东西,例如:
I'm trying to install a Rust crate on my system (Arch Linux) using Cargo. 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
这是什么意思?我必须首先从源代码构建它吗?如果不首先安装Cargo,那有什么意义呢?
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?
$ 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 install
is used to install binary packages that happen to be distributed through crates.io.
如果要使用板条箱作为依赖项,请将其添加到您的Cargo.toml
.
If you want to use a crate as a dependency, add it to your Cargo.toml
.
阅读 The Rust入门指南和《货物入门指南》 获取更多信息.简而言之:
Read the Rust getting started guide and the Cargo getting started guide for further information. In short:
cargo new my_project
cd my_project
echo 'curl = "0.3.0"' >> Cargo.toml
有趣的是,您可以使用cargo install
,可以更轻松地修改您的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 add curl
要注意的重要一点是,每个货物项目都管理和编译了一组独立的依赖项(某些背景信息).因此,安装已编译库没有任何意义.库的每个版本的源代码将被本地缓存,从而避免了多次下载.
An important thing to note is that every Cargo project manages and compiles a separate set of dependencies (some background info). 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.
这篇关于通过货物安装周转箱时出错:指定的软件包没有二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!