Search code examples
rustdependenciesrust-cargorust-crates

How do I use external crates in Rust?


I'm trying to work with the rust-http library, and I'd like to use it as the basis for a small project.

I have no idea how to use something that I can't install via rustpkg install <remote_url>. In fact, I found out today that rustpkg is now deprecated.

If I git clone the library and run the appropriate make commands to get it built, how do I use it elsewhere? I.e. how do I actually use extern crate http?


Solution

  • Update

    For modern Rust, see this answer.


    Original answer

    You need to pass the -L flag to rustc to add the directory which contains the compiled http library to the search path. Something like rustc -L path-to-cloned-rust-http-repo/build your-source-file.rs should do.

    Tutorial reference