Referring to a local crate generated with cargo init

i'm having this problem where i have a folder /rust/ in which there are two crates generated with cargo init rust/crate_one and rust/crate_two

I have added to crate_two 's Cargo.toml under dependencies: crate_one = { path = "../crate_one/", version = "0.1.0" } . When trying to use extern crate crate_one in rust/crate_two/ and running cargo run from rust/crate_two , I get an extern crate not found error.

Any advice?

What version is set in crate_one's Cargo.toml?


Problem: cargo init creates a binary by default, not a Rust library; so it cannot be used as a dependency by another Rust crate. You need to have a src/ file in crate_one/

More generally, if you intend to crate a crate to be used as a library, then you need to pass the --lib flag when creating it: cargo init --lib (and cargo new --lib <name> if creating a subdir at the same time).


Thank you, that makes a lot of sense!

For future people, has helped to me learn more.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.