Unable to find symbols from external boxes included in `use`
I am trying to use some Rust libraries from boxes on Github. This is the first time I've tried this. The code taken from the "html" library example starts 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() {}
The 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 file Cargo.toml
contains
[dependencies.http]
http = "https://github.com/chris-morgan/rust-http"
[dependencies.url]
url = "0.2.7"
and HTTP and URL packages were found and extracted earlier cargo build
.
Strings extern crate http
and extern crate url
do not generate errors; the combiners detect crates, but those crates do not appear to contain the expected characters. If I add "extern crate foo" I get an error so it gets checked.
This is probably some sort of problem finding Rust or Cargo for libraries. Rust is installed to ~/local
, not as root, is done by setting a parameter --prefix
during installation. Maybe it broke something, although Cargo has to deal with it. Basic stuff like "hello_world" works great; bring to external libraries no.
I noticed that cargo update
it is not causing the http and url boxes to be resampled 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-night (e11c317 2014-12-21 20:43:45 +0000)
source to share
The compiler gave you the answer you need.
Your operators extern crate
are inside a module, and operators use
require absolute paths. That is, when you say use url::Url;
inside a module interactive_test
, what you are actually saying is "use url::Url
which is defined in the root module", which is not the case.
What you need to do is prefix the path with with self::
so that it can look it up in the current module. You can also use super::
to access the parent module (if it ever appears).
I personally get around this by putting all my statements extern crate
in the root module, which also serves as a kind of programmatic list of external boxes in use.
source to share