Hello all, I'm currently using CXX to do rust/C++ interop with the rust code being built as a static library that is linked to the C++ code (As in the example here). I'm able to get this to work when I build the C++ in release mode.
But I am unable to build the C++ code in debug mode because rust is hard coded to use the release CRT:
blobstore.lib(bbea27b962738898-cxx.o) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
blobstore.lib(bbea27b962738898-cxx.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.obj
Based on Chris' comments here: Windows MSVC CRT linking · Issue #211 · rust-lang/libs-team · GitHub
I need to use nodefaultlib to override the CRT but when I try to do this, the build doesn't seem to respect my configurations
I have tried to make this change in the .cargo/config.toml file:
Plain Text
[target.'cfg(all(target_os="windows"))']
rustflags = [
"-C", "target-feature=-crt-static", "-Ccontrol-flow-guard",
"-C", "link-arg=/NODEFAULTLIB:msvcrt.lib -lmsvcrtd",
"-C", "link-arg=/NODEFAULTLIB:msvcprt.lib -lmsvcprtd",
"-C", "link-arg=/DEFAULTLIB:msvcrtd.lib",
"-C", "link-arg=/DEFAULTLIB:msvcprtd.lib",
]
as well as via environment variables (in cmake):
Plain Text
add_custom_command(
OUTPUT ${BLOBSTORE_BRIDGE_CPP} ${BLOBSTORE_LIB}
COMMAND ${CMAKE_COMMAND} -E env "RUSTFLAGS=-Clink-arg=/nodefaultlib:msvcrt.lib -Clink-arg=/defaultlib:msvcrtd.lib -Clink-arg=/nodefaultlib:msvcprt.lib -Clink-arg=/defaultlib:msvcprtd.lib"
COMMAND cargo build --manifest-path ${CARGO_MANIFEST} --verbose
DEPENDS ${BLOBSTORE_SOURCE_FILE}
USES_TERMINAL
COMMENT "Running cargo..."
)
Has anyone had any luck with rust/c++ interop on windows using CXX in debug mode?