link 带有 //MT 标志的 exe

link exe with //MT flag

我想在 windows 上构建 exe 文件, 不需要 vcruntime。

所以我尝试了:

.cargo/config
[target.i686-pc-windows-msvc]
rustflags = ["-Clink-args=/MT"]

看起来像 cargo found 配置,因为 cargo 重建 整个项目,但是 dumpbin /DEPENDENTS test.exe 仍然显示 VCRUNTIME140.dll 作为依赖项, 有什么想法 link VCRUNTIME140 是静态的吗?

看到这个rfc

你可以用 rustc nightly 试试:

c:\Users\IEUser\test2>rustc -Z unstable-options -C target-feature=+crt-static test.rs

user1034749 答案与 rustc 有关。如果你想用货物做这个,信息在这里:https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md

RUSTFLAGS='-C target-feature=+crt-static' cargo build --target x86_64-pc-windows-msvc