How to import crates properly?

This is my very project using Rust where I want to use "windows" crate

[package]
name = "capture"
version = "0.1.0"
edition = "2021"

[dependencies]
windows = { version = "0.59.0", features = ["Win32_Graphics_Dxgi"]}

use windows::Win32::Graphics::Dxgi;

fn main() {
    println!("Hello, world!");
}
error[E0433]: failed to resolve: could not find `Win32` in `windows`
 --> src/main.rs:1:14
  |
1 | use windows::Win32::Graphics::Dxgi;
  |              ^^^^^ could not find `Win32` in `windows`

For more information about this error, try `rustc --explain E0433`.

Can someone tell what I am doing is it fundamentally wrong or is this something specific I use WSL2 for development

can you double check the features are enabled correctly? e.g. what's the output of:

$ cargo tree --format "{p} - {f}"
cargo tree --format "{p} - {f}"
capture v0.1.0 (/mnt/d/Rust/capture) -
└── windows v0.59.0 - Win32,Win32_Foundation,Win32_Graphics,Win32_Graphics_Dxgi,default,std
    ├── windows-core v0.59.0 - std
    │   ├── windows-implement v0.59.0 (proc-macro) -
    │   │   ├── proc-macro2 v1.0.92 - default,proc-macro
    │   │   │   └── unicode-ident v1.0.14 -
    │   │   ├── quote v1.0.38 - default,proc-macro
    │   │   │   └── proc-macro2 v1.0.92 - default,proc-macro (*)
    │   │   └── syn v2.0.95 - clone-impls,derive,full,parsing,printing,proc-macro
    │   │       ├── proc-macro2 v1.0.92 - default,proc-macro (*)
    │   │       ├── quote v1.0.38 - default,proc-macro (*)
    │   │       └── unicode-ident v1.0.14 -
    │   ├── windows-interface v0.59.0 (proc-macro) -
    │   │   ├── proc-macro2 v1.0.92 - default,proc-macro (*)
    │   │   ├── quote v1.0.38 - default,proc-macro (*)
    │   │   └── syn v2.0.95 - clone-impls,derive,full,parsing,printing,proc-macro (*)
    │   ├── windows-result v0.3.0 - std
    │   │   └── windows-targets v0.53.0 -
    │   │       └── windows_x86_64_gnu v0.53.0 -
    │   ├── windows-strings v0.3.0 - std
    │   │   └── windows-targets v0.53.0 -  (*)
    │   └── windows-targets v0.53.0 -  (*)
    └── windows-targets v0.53.0 -  (*)

This is the result I don't quite get it, but I think imports are correct even after this is still showing the not found error

the features are enabled, all looks good to me, I don't know why you can the error.

btw, what's the full error message, if you use --verbose flag for cargo? e.g.:

$ cargo build -vvv
error[E0433]: failed to resolve: could not find `Win32` in `windows`
 --> src/main.rs:1:14
  |
1 | use windows::Win32::Graphics::Dxgi;
  |              ^^^^^ could not find `Win32` in `windows`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `capture` (bin "capture") due to 1 previous error

Caused by:
  process didn't exit successfully: `CARGO=/home/shreyansh14/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo CARGO_BIN_NAME=capture CARGO_CRATE_NAME=capture CARGO_MANIFEST_DIR=/mnt/d/Rust/capture CARGO_MANIFEST_PATH=/mnt/d/Rust/capture/Cargo.toml CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=capture CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 LD_LIBRARY_PATH='/mnt/d/Rust/capture/target/debug/deps:/home/shreyansh14/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib' /home/shreyansh14/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name capture --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=120 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=a39ca00effa6b669 -C extra-filename=-a39ca00effa6b669 --out-dir /mnt/d/Rust/capture/target/debug/deps -C incremental=/mnt/d/Rust/capture/target/debug/incremental -L dependency=/mnt/d/Rust/capture/target/debug/deps --extern capture=/mnt/d/Rust/capture/target/debug/deps/libcapture-8ffb0736ac87b3a0.rlib --extern windows=/mnt/d/Rust/capture/target/debug/deps/libwindows-43f409e5f34adc72.rlib -L native=/home/shreyansh14/.cargo/registry/src/index.crates.io-6f17d22bba15001f/windows_x86_64_gnu-0.53.0/lib` (exit status: 1)

Are you trying this in some non-Windows environment? If yes, you need to explicitly use correct target, i.e. rustup target add x86_64-pc-windows-gnu and then cargo build --target=x86_64-pc-windows-gnu.

1 Like

Yes I do use WSL2 (windows subsystem linux) for development, I used the commands that you gave.

Now it's working thanks for your help @Cerber-Ursi and @nerditation