6

I am currently learning Rust, and for that purpose I wanted to create my own crate and use it. However, Rust can't find this crate.

I have the following file structure:

├───minimal
│    ├───Cargo.toml
│   └───src
│       └───main.rs
└───util
    └───win
        ├───Cargo.toml
        └───src
            └───lib.rs

In folder minimal I have my main project. It looks like this:

Cargo.toml

[package]
name = "minimal"
version = "0.1.0"
[dependecies]
win = { path = "../util/win"}

main.rs

extern crate win; // ERROR: "Can't find crate for 'win' rustc(E0463)"
fn main() {
    println!("Hello, World!");
}

My library in folder win looks like this:

File Cargo.toml

[package]
name = "win"
version = "0.1.0"

File lib.rs

pub type TestType = String;

My first assumption was that I somehow had a mistake in specifying the path in the dependency of the Cargo.toml file. So I tried to wiggle it around a bit, but it does not seem to work.

Rust reports

can't find crate for 'win' rustc(E0463)

I feel like I am making a very basic error here, however, when looking at similar questions (e.g., How do I "use" or import a local Rust file?) I can't seem to find it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user2089648
  • 1,356
  • 2
  • 17
  • 31
  • Have you tried with an absolute path to see if that works? – 8176135 Dec 07 '19 at 21:09
  • I have tried it, yes - unfortunately it didn't work. Do I need to compile my library in a specific way for this to work? – user2089648 Dec 07 '19 at 21:12
  • Don't think so... I just replicated your setup and can't get the same error. Another thing to try could be to use the 2018 edition, though I doubt it will matter. – 8176135 Dec 07 '19 at 21:19
  • Just to check, you are using `cargo` to build/run this right? I.e. Running `cargo run` in the minimal directory – 8176135 Dec 07 '19 at 21:23
  • I use `cargo run` to run this, yes.I installed rust from here: https://www.rust-lang.org/tools/install and I run it from visual studio code in windows 10. (I get the same error if I use the cmd-prompt directly.) Strange that it works out of the box for you. – user2089648 Dec 07 '19 at 21:26
  • @user2089648 It works for me too. No errors. – Kentaro Okuda Dec 07 '19 at 21:34
  • Have you created any additional files except the four I use? – user2089648 Dec 07 '19 at 22:18
  • @user2089648 No additional files. Mine looks just like yours. – Kentaro Okuda Dec 07 '19 at 23:33

1 Answers1

12

After having a good night's sleep and looking at this problem again, I have managed to find the error.
I used [dependecies] instead of [dependencies] in the Cargo.toml file.

On the one hand, I feel kind of dumb for this error, but on the other hand I now know that Cargo will not warn about unknown tags in the TOML file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user2089648
  • 1,356
  • 2
  • 17
  • 31