This took us a while to figure out. A Rust "staticlib" debug-build outputs a LIB which references MSVCRT. This is not suitable for linking with C++ code built using MSVC debug settings (/MDd), which requires everything to use only MSVCRTD. To get a Rust LIB which references MSVCRTD appears to require CFLAGS=-MDd and CXXFLAGS=-MDd set in the Windows environment (e.g. set CFLAGS=-MDd etc at CMD prompt). This works because cc crate picks these up when it calls cl.exe. In our use-case this caused all the mentions of MSVCRT in the dumpbin /all output for the generated LIB to be replaced with MSVCRTD. Then the link of the LIB to debug C++ code succeeds.
So the question is where this should be documented. It is no use documenting this in cc crate, because that is deep down the crate tree and no-one is going to look there. Perhaps people don't even realize that cc crate is being used. Since it's often someone directly using cxx crate to interface to C++ who would hit this problem, it would likely be helpful to document it in the cxx.rs pages.
(Thanks for cxx crate, by the way -- it helped us a lot!)
This took us a while to figure out. A Rust "staticlib" debug-build outputs a LIB which references MSVCRT. This is not suitable for linking with C++ code built using MSVC debug settings (/MDd), which requires everything to use only MSVCRTD. To get a Rust LIB which references MSVCRTD appears to require
CFLAGS=-MDdandCXXFLAGS=-MDdset in the Windows environment (e.g.set CFLAGS=-MDdetc at CMD prompt). This works becausecccrate picks these up when it callscl.exe. In our use-case this caused all the mentions of MSVCRT in thedumpbin /alloutput for the generated LIB to be replaced with MSVCRTD. Then the link of the LIB to debug C++ code succeeds.So the question is where this should be documented. It is no use documenting this in
cccrate, because that is deep down the crate tree and no-one is going to look there. Perhaps people don't even realize thatcccrate is being used. Since it's often someone directly usingcxxcrate to interface to C++ who would hit this problem, it would likely be helpful to document it in thecxx.rspages.(Thanks for
cxxcrate, by the way -- it helped us a lot!)