Support for MSVC -MTd and -MDd
Closed this issue · 7 comments
The CMake documentation lists additional debug variants
for these MSVC flags, but as far as I can tell, the cc crate doesn't support the debug variants.
It doesn't support it because the rest of the rust ecosystem doesn't either. Fixing this would require a much more coordinated effort across multiple repos, and still would have an ugly transition period.
Yeah I tried it and have to revert it, as it breaks rust compilation
The core issue is that rustc doesn't support this so there's no way for cc
to know if this was wanted. cc
could have a function for overriding the CRT libraries if someone really knows what they're doing but it is a bit of a footgun because it's super important that everything uses the same C runtime libraries.
To recap, this is the current state of affairs:
C/C++ | rustc | Native libs |
---|---|---|
/MT |
+crt-static |
libcmt, libvcruntime, libucrt |
/MTd |
❌ | libcmtd, libvcruntimed, libucrtd |
/MD |
-crt-static |
msvcrt, vcruntime, ucrt |
/MDd |
❌ | msvcrtd, vcruntimed, ucrtd |
So compiling using rustc only has two options. You can override Rust's choices by using a linker argument. E.g. /NODEFAULTLIB:msvcrt /DEFAULTLIB:msvcrtd
to use the debug libraries. But you need some way to coordinate that choice with everyone and everything else.
So compiling using rustc only has two options. You can override Rust's choices by using a linker argument. E.g. /NODEFAULTLIB:msvcrt /DEFAULTLIB:msvcrtd to use the debug libraries.
If it is possible to override using a linker argument, then maybe we can add a new flag/env to use the debug version of msvc runtime?
Related issue: rust-lang/rust#39016
An environment variable might work to keep it consistent across the whole build.
We also need to keep in mind a future where rustc hopefully gains support for the debug CRTs. Then we'd just need to query it the same way we do crt-static
.
Thank you for the information everyone!
I guess in my case I'll just have to force my CMake C++ dependency to build without debug support.