I am working on a rust project and trying to get Winapi working.
This is my Cargo.toml
:
[package]
name = "sacl"
version = "0.1.0"
edition = "2021"
[dependencies]
winapi = "0.3.5"
And this is my main.rs
:
extern crate winapi;
use winapi::um::winnt::*;
fn main() {
println!("Hello, world!");
}
But for some reason whenever I run cargo build
I get the following error:
error[E0433]: failed to resolve: could not find `um` in `winapi`
--> src/main.rs:3:13
|
3 | use winapi::um::winnt::*;
|
I have tried including um
as a feature in Cargo.toml since I read that winapi features are gated. Not finding anything about errors with um
.
To use winapi::um::winnt
you have to include the feature winnt
in your Cargo.toml.
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.5", features = ["winnt"] }
The crate uses the last module name as the feature name. So for winapi::winrt::activation
you would use activation
for the feature.
Appendix cross compilation:
The modules of winapi
are only available if cfg(windows)
is present due to its conditional compilation. If you target windows but write the source code on a different platform, make sure to setup cross compilation as noted by iceburg in the comment section.