通过货物安装板条箱时出错:指定的包没有二进制文件 [英] Error installing a crate via cargo: specified package has no binaries

查看:15
本文介绍了通过货物安装板条箱时出错:指定的包没有二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

If you want to use a crate as a dependency, add it to your Cargo.toml.

阅读Rust 获得入门指南Cargo 入门指南 了解更多信息.简而言之:

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-edit 的第三方 Cargo 子命令>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


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


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆