I'm trying to use some Rust libraries from crates on Github. This is the first time I've tried to do this. The code, lifted from an "html" library example, begins like this:
mod interactive_test {
extern crate http;
extern crate url;
use std::os;
use std::str;
use url::Url;
use http::client::RequestWriter;
use http::method::Get;
use http::headers::HeaderEnum;
// ...
}
fn main() {}
Errors look like this:
error[E0432]: unresolved import `url::Url`
--> src/main.rs:7:9
|
7 | use url::Url;
| ^^^^^^^^ Did you mean `self::url`?
error[E0432]: unresolved import `http::client::RequestWriter`
--> src/main.rs:9:9
|
9 | use http::client::RequestWriter;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Did you mean `interactive_test::http`?
error[E0432]: unresolved import `http::method::Get`
--> src/main.rs:10:9
|
10 | use http::method::Get;
| ^^^^^^^^^^^^^^^^^ Did you mean `self::http::method`?
error[E0432]: unresolved import `http::headers::HeaderEnum`
--> src/main.rs:11:9
|
11 | use http::headers::HeaderEnum;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ Did you mean `interactive_test::http`?
The Cargo.toml
file contains
[dependencies.http]
http = "https://github.com/chris-morgan/rust-http"
[dependencies.url]
url = "0.2.7"
and the HTTP and URL packages were found and fetched by cargo build
earlier.
The extern crate http
and extern crate url
lines do not generate errors; the crates are being found by the compiler, but those crates don't seem to contain the expected symbols. If I add `extern crate foo", I get an error, so that is checked.
This is probably some problem with how Rust or Cargo search for libraries. Rust is installed in ~/local
, not as root, done by setting the --prefix
parameter during installation. That may have broken something, although Cargo should handle that. Basic stuff like "hello_world" works fine; bringing in external libraries does not.
I notice that cargo update
doesn't cause a re-fetch of the http and url crates from Github. The documentation indicates that it should.
Versions:
- Ubuntu 14.04 LTS.
- rustc 0.13.0-nightly (96a3c7c6a 2014-12-23 22:21:10 +0000)
- cargo 0.0.1-pre-nightly (e11c317 2014-12-21 20:43:45 +0000)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…