Link with static C++ library on Windows fails in debug but not in release

Hi all, I have a weird linking problem where I've tried several different things but I cannot get it to work. Here is the short version:

Context: I am on Windows 10, using Rust 1.73.0 stable (installed via rustup)

Overview:
I have a rust binary project that links to a static library mylibrary.lib. That library is actually built using the cmake crate as part of my build.rs. When I build the project in debug mode using cargo build, I get a linker error like so:

          LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
          mylibrary.lib(client.obj) : error LNK2019: unresolved external symbol __imp__invalid_parameter referenced in function "void * __cdecl std::_Allocate<16,struct std::_Default_allocate_traits,0>(unsigned __int64)" (??$_Allocate@$0BA@U_Default_allocate_traits@std@@$0A@@std@@YAPEAX_K@Z)
          mylibrary.lib(util.obj) : error LNK2001: unresolved external symbol __imp__invalid_parameter
          mylibrary.lib(client.obj) : error LNK2019: unresolved external symbol __imp__calloc_dbg referenced in function "char * __cdecl std::_Maklocstr<char>(char const *,char *,struct _Cvtvec const &)" (??$_Maklocstr@D@std@@YAPEADPEBDPEADAEBU_Cvtvec@@@Z)
          mylibrary.lib(util.obj) : error LNK2001: unresolved external symbol __imp__calloc_dbg
          mylibrary.lib(client.obj) : error LNK2019: unresolved external symbol __imp__CrtDbgReport referenced in function "void * __cdecl std::_Allocate<16,struct std::_Default_allocate_traits,0>(unsigned __int64)" (??$_Allocate@$0BA@U_Default_allocate_traits@std@@$0A@@std@@YAPEAX_K@Z)
          mylibrary.lib(util.obj) : error LNK2001: unresolved external symbol __imp__CrtDbgReport
          C:\code\application\target\debug\deps\application.exe : fatal error LNK1120: 3 unresolved externals

However, when I build it in release mode cargo build --release, then it just works. So I understand that the debug build of the library will link against symbols that are missing. I've tried giving the /MTd as cflags and cxxflags to the cmake crate to no avail. I also tried adding a .cargo/config.toml with the following contents:

[build]
rustflags = ["-C", "target-feature=+crt-static"]

That now gives me the same error in release mode as in the debug mode.

I am assuming I must be doing some stupid little mistake but if more context is needed, I can gladly provide it. I appreciate all suggestions that help me try out new things.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.