0

I use Visual Studio 2017 to open cmake projects. I have a debug application which uses MDd runtime library - CMAKE_CXX_FLAGS_DEBUG:/MDd /Zi /Ob0 /Od /RTC1. When I try to link to a release static library (MD runtime) I get the following errors:

error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.cpp.obj
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.cpp.obj

I can build a debug static library (MDd runtime library) and link to it but I wonder if there is any workaround for that issue ?

Irbis
  • 1,432
  • 1
  • 13
  • 39
  • 2
    "I wonder if there is any workaround for that issue?" - What kind of "workaround" do you ask for? You cannot link executable with a library which has different CRT settings. No way. See e.g. that question: https://stackoverflow.com/questions/14714877/mismatch-detected-for-runtimelibrary. – Tsyvarev Jan 14 '21 at 19:12

1 Answers1

1

I have a debug application which uses MDd runtime library

/MDd means your application is using the "debug multithread-specific and DLL-specific version of the run-time library".

When I try to link to a release static library (MD runtime)

/MD means the library is using the "multithread-specific and DLL-specific version of the run-time library". That is not a "release static library", the library is using the DLL version of the CRT, and that CRT is shared with your application. This requires the debug vs. release options to match between the application build and the library build, and there is no possible way to circumvent that. From the documentation page:

All modules passed to a given invocation of the linker must have been compiled with the same run-time library compiler option

dxiv
  • 16,984
  • 2
  • 27
  • 49