0xQuasar
0xQuasar

Reputation: 33

Rust compiler/cargo cannot find crate which is installed

I am a Rust beginner and am having difficulty getting dependencies to work using Cargo. I'm following the docs on how to import crates.

In Cargo.toml I have added:

[dependencies]
ferris-says = "0.2"

Then I ran cargo build.

I have main.rs in src/main.rs. In it I attempt to import the ferris-says crate:

use ferris_says::say;

However when I run rustc main.rs, the compiler cannot find the crate ferris-says. Error:

1 | use ferris_says::say; // from the previous step
  |     ^^^^^^^^^^^ maybe a missing crate `ferris_says`?

I have followed the docs exactly (https://www.rust-lang.org/learn/get-started) and tried many times.

I have tried on different OS (Mac, Ubuntu) My Rust is 1.64.0.

Upvotes: 2

Views: 1170

Answers (1)

Aleksander Krauze
Aleksander Krauze

Reputation: 6205

when I run rustc main.rs

rustc is a rust compiler, you don't need to use it directly. Use cargo, a build system that will manage your dependencies and invoke rustc with proper flags. So try cargo build.

Upvotes: 3

Related Questions