Statically linking to CRT on MSVC

Hi guys,

I'm trying to create an executable in rust and want it to be linked statically to the CRT. I've tried putting the following in the Cargo.toml:

[target.x86_64-pc-windows-msvc]
rustflags = ["-C target-feature=+crt-static"]

but when I run cargo build it throws the following warning:

warning: unused manifest key: target.x86_64-pc-windows-msvc.rustflags

What am I doing wrong?

Note:I'm using the latest nightly.

Don't put it in your Cargo.toml, instead put it in your .cargo\config.

[target.x86_64-pc-windows-msvc]
rustflags = ["-Ctarget-feature=+crt-static", "-Zunstable-options"]
4 Likes

Thanks retep998 :slight_smile: . Should have read the cargo documentation properly.

Can I enable statically linkage to MSVC CRT only for release build?

I also want this feature, but it seems that I haven't found a way yet...