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:

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.

rustflags = ["-Ctarget-feature=+crt-static", "-Zunstable-options"]


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