Building with rustc: cannot find crate

hi im trying to build my code with rustc but it cannot find crate which is installed with cargo and also running code with $ cargo run successfully runs the code.
Any ideas?

use glob::glob;

fn main() {
    for entry in glob("/home/user/*.jpg").unwrap(){
        match entry {
            Ok(path) => println!("{:?}", path.display()),
            Err(e) => println!("{:?}",e),


Toml file

name = "test1"
version = "0.1.0"
authors = ["ieuD <>"]
edition = "2018"

# See more keys and their definitions at

glob = "0.3.0"


╰─ rustc src/
error[E0432]: unresolved import `glob`
 --> src/
1 | use glob::glob;
  |     ^^^^ maybe a missing crate `glob`?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
1 Like

If you use rustc without cargo, you must explicitly tell him where to look for dependencies. Try doing cargo build -v to see how cargo do it itself, or check rustc documentation to find out.


with cargo dependency installation. how can i locate my installed dependencies ? Would you give me an example standart path ? or command?

Cargo doesn't have any way to “install” libraries. (cargo install is only for binaries.)

If you have previously built your project using Cargo, the dependencies will be in your target folder, and you can use cargo build -v to see how to pass them to rustc. Otherwise, you can compile each dependency separately, then pass rustc the locations where you compiled them.

1 Like

Cargo is not just an installer, but a whole build system that manages dependencies. You generally can't use just rustc if you want to use cargo dependencies (you'd have to reinvent all of cargo).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.