snippetrustCritical
How to use a local unpublished crate?
Viewed 0 times
howunpublishedcrateuselocal
Problem
I've made a library:
and I want to use that library in a different program:
what do I need to do to get this to work?
They aren't in the same project folder.
Hopefully this makes sense.
I thought I'd be able to override the path as per the Cargo guide, but it states
You cannot use this feature to tell Cargo how to find local unpublished crates.
This is when using the latest stable version of Rust (1.3).
cargo new my_liband I want to use that library in a different program:
cargo new my_program --binextern crate my_lib;
fn main {
println!("Hello, World!");
}what do I need to do to get this to work?
They aren't in the same project folder.
.
├── my_lib
└── my_programHopefully this makes sense.
I thought I'd be able to override the path as per the Cargo guide, but it states
You cannot use this feature to tell Cargo how to find local unpublished crates.
This is when using the latest stable version of Rust (1.3).
Solution
Add a dependency section to your executable's Cargo.toml and specify the path:
or the equivalent alternate TOML:
Check out the Cargo docs for specifying dependencies for more detail, like how to use a git repository instead of a local path.
[dependencies.my_lib]
path = "../my_lib"or the equivalent alternate TOML:
[dependencies]
my_lib = { path = "../my_lib" }Check out the Cargo docs for specifying dependencies for more detail, like how to use a git repository instead of a local path.
Code Snippets
[dependencies.my_lib]
path = "../my_lib"[dependencies]
my_lib = { path = "../my_lib" }Context
Stack Overflow Q#33025887, score: 348
Revisions (0)
No revisions yet.