1

I am trying to understand how to use local crates. I have the same problem as specified in How to use a local unpublished crate?, but the answers do not solve my problem. File structure:

|--my_program
|   |--Cargo.toml  
|   |--src
|      |--main.rs
|
|--my_lib
    |--Cargo.toml  
    |--src
       |--main.rs

my_lib/main.rs :

fn main() {}

my_lib/Cargo.toml :

[package]
name = "my_lib"
version = "0.1.0"
authors = ["test"]
edition = "2018"

[dependencies]

my_program/main.rs :

fn main() {}

my_program/Cargo.toml :

[package]
name = "my_lib"
version = "0.1.0"
authors = ["test"]
edition = "2018"

[dependencies]
my_lib = { path = "../my_lib" }

Out:

error[E0463]: can't find crate for `my_lib`

Windows 10, rustc 1.47

I can use std:: crates as well as download crates like clap, but i can't figure our how to use a local crate. I have also tried "use" instead of "extern crate", which is supposed to do the same, but I also get an error (error[E0432]: unresolved import my_lib) saying no'my_lib' external crate.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
  • are you sure ? check twice the lib name in your toml. also be sure that "my_lib" IS a lib that HAVE a lib.rs file – Stargateur Nov 06 '20 at 23:40
  • 2
    A crate with `main.rs` creates a binary, not a library. You cannot import from a binary. Rename `my_lib/main.rs` to `my_lib/lib.rs` (or create it with `cargo new --lib`). – Shepmaster Nov 07 '20 at 03:20

0 Answers0