Statically linking to CRT on MSVC


#1

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.


#2

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"]

#3

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