只需在当前根目录下新建.cargo\config.toml,写入以下配置
├── .cargo
│ └── config.toml
├── Cargo.lock
├── Cargo.toml
└── src
└── main.rs
[target.'cfg(all(windows, target_env = "msvc"))']
rustflags = ["-C", "target-feature=+crt-static"]
use windows::{core::h, Win32::UI::WindowsAndMessaging::{MessageBoxW, MB_OK}};
fn main() {
unsafe{
MessageBoxW(None, h!("Demo"), h!("自带vcruntime140.dll"), MB_OK);
}
}
[package]
name = "rust_vc_runtime"
version = "0.1.0"
edition = "2021"
[dependencies.windows]
version = "0.58.0"
features = [
"Win32_UI_WindowsAndMessaging",
"Win32_UI_Shell"
]