我正在尝试使用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这是什么意思?我必须首先从源代码构建它吗?如果货物一开始就不安装,那它还有什么用呢?
$ 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)发布于 2016-06-08 23:40:18
cargo install用于安装碰巧通过crates.io分发的二进制软件包。
如果你想使用一个板条箱作为依赖,将它添加到你的Cargo.toml中。
有关更多信息,请阅读the Rust getting started guide和the Cargo getting started guide。简而言之:
cargo new my_project
cd my_project
echo 'curl = "0.3.0"' >> Cargo.toml有趣的是,您可以使用cargo install安装名为cargo-edit的第三方货运子命令,这使得修改Cargo.toml文件以添加依赖项变得更容易!
cargo install cargo-edit
cargo add curl需要注意的重要一点是,每个 Cargo项目都管理和编译一组独立的依赖项(some background info)。因此,安装一个已编译的库是没有意义的。库的每个版本的源代码都将被缓存在本地,避免多次下载。
另请参阅:
https://stackoverflow.com/questions/37706999
复制相似问题