Wheat Wizard
Wheat Wizard

Reputation: 4219

Unable to find crate when compiling even after successfully running `cargo build`

I've been trying to compile a project written in Rust. When I first compiled, I got the error

error[E0463]: can't find crate for `argparse`
 --> src/main.rs:6:1
  |
6 | extern crate argparse;
  | ^^^^^^^^^^^^^^^^^^^^^^ can't find crate

This seemed like a dependency error meaning that I needed to use Cargo. Luckily, the project provided a Cargo.toml file for me to use. I ran cargo build successfully and attempted to compile the Rust source again.

The error persisted so I opened up the Cargo.toml to take a look. It contained what I would have expected

[package]
name = "stones"
version = "0.5.0"
authors = ["cheezgi <[email protected]>"]

[dependencies]
argparse = "*"
rustyline = "*"

[profile.dev]
debug = true

I ran cargo build -v to make sure everything was going as expected.

       Fresh unicode-width v0.1.4
       Fresh bitflags v0.4.0
       Fresh libc v0.2.20
       Fresh argparse v0.2.1
       Fresh encode_unicode v0.1.3
       Fresh nix v0.5.1
       Fresh rustyline v1.0.0
       Fresh stones v0.5.0 (file:///Users/eamonolive/projects/stones)
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs

I couldn't see anything wrong with the results here, it looked like everything was installed properly but the compiler continues to be unable to find the crate for argparse.

I'm using rustc 1.19.0 if it makes any difference.

Upvotes: 0

Views: 904

Answers (1)

Shepmaster
Shepmaster

Reputation: 431779

I ran cargo build successfully and attempted to compile the Rust source again.

Cargo runs the compiler for you. By calling cargo build, you have already implicitly called the compiler (rustc) and the program is built and ready to be executed: cargo run or ./target/debug/my-app-name.

It's a very rare occurrence to call rustc directly.

Upvotes: 4

Related Questions