hi.
- I made a lib with ( cargo new lib delta )
- write code in src/lib.rs
- run cargo build
now, how use this lib inside another project ??
- need to copy target files ??
hi.
now, how use this lib inside another project ??
A library is a crate (indicated by the Cargo.toml
in the root directory). To use it, you must specify this crate as a dependency of the one you will use it from. If you want to use it locally, you can create a non-library crate and specify in the Cargo.toml
:
[dependencies]
my_super_library = { path = "../path/to/my_super_library" }
You have all the details in the docs: Specifying Dependencies - The Cargo Book
thanks. work great.
when i use that lib in my project like you said.
then when i compiled project and i want upload on somewhere
i need upload this lib seperate on same directory ??
or crate itself make a copies from that lib when done
cargo build ??
cargo compiles it again when used in another project. Rust uses static linking
The library itself is a separate package. If you want to have both in the same place, you can create a Cargo workspace which is in reality just a directory with a workspace file and one directory for each crate inside (one for your lib and one for your app).
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.