1

I've made a new project with

cargo new project-name
cd ./project-name

And once in the directory running

cargo install crate-name

for any crate listed on crates.io yields the error

Updating crates.io index
Installing crate-name version-number                                                    
error: specified package has no binaries

Looking elsewhere suggests adding the proper dependencies to my Cargo.toml file, but this does not change the output I'm getting. In particular I'm trying to install rust-gmp as a project dependency, and having

[dependencies]
rust-gmp = "0.5.0"

in Cargo.toml does not allow me to install rust-gmp. Any suggestions?

  • The command is `cargo build` for building the project, `cargo run` for running the main binary application, and `cargo install` to install the local project. `cargo install crate-name` only works if the crate is already published on [crates.io](//crates.io). See also the Cargo guide on [creating a new package](https://doc.rust-lang.org/cargo/guide/creating-a-new-project.html). – E_net4 Jan 07 '19 at 23:04
  • Trying to install rust-gmp as a dependency for my project. It seems to be listed on crates.io (https://crates.io/crates/rust-gmp) – Michael Straka Jan 07 '19 at 23:14
  • Done. I get the same error for any crate listed on crates.io though; I can't seem to install any crate as a dependency. – Michael Straka Jan 07 '19 at 23:23

1 Answers1

2

Dependencies are not actually "installed", by Cargo's nomenclature. Instead, as you already did, you add the crate as a dependency of a project in Cargo.toml.

Thus, whenever you run a subcommand which requires those dependencies in some way (e.g cargo build, cargo check, cargo run, etc.), they will be automatically downloaded and compiled for you.

See also the Cargo guide on managing dependencies.

E_net4
  • 27,810
  • 13
  • 101
  • 139
  • 1
    Thanks! Figured out the problem, needed to write `extern crate gmp;` in place of `extern crate rust-gmp;` when importing the package. – Michael Straka Jan 07 '19 at 23:44