Linking against debug MS VC++ Runtime
โ Rust ๐ 2025-09-26 ๐ค surdeus ๐๏ธ 9On Windows even in Debug mode Rust still links against the Release runtime.
This is annoying, since the C++ library Rust interacts with is linked against Debug runtime, which causes conflicts.
I found this issue: rustc always links against non-debug Windows runtime ยท Issue #39016 ยท rust-lang/rust ยท GitHub
It says that I can use this code to use Debug runtime instead:
// Don't link the default CRT
println!("cargo::rustc-link-arg-bins=/nodefaultlib:msvcrt");
// Link the debug CRT instead
println!("cargo::rustc-link-arg-bins=/defaultlib:msvcrtd");
The problem with this code, however, is that I cannot run this as a part of a Rust library build.rs script, as I get this error:
error: invalid instruction `cargo::rustc-link-arg-bins` from build script
I tried setting cargo::rustc-link-lib instead, but this failed also:
// Don't link the default CRT
println!("cargo::rustc-link-lib=/nodefaultlib:msvcrt");
// Link the debug CRT instead
println!("cargo::rustc-link-lib=/defaultlib:msvcrtd");
...
error: renaming of the library `/nodefaultlib` was specified, however this crate contains no `#[link(...)]` attributes referencing this library
error: renaming of the library `/defaultlib` was specified, however this crate contains no `#[link(...)]` attributes referencing this library
Can anything be done now?
3 posts - 2 participants
๐ท๏ธ Rust_feed