'MT_StaticRelease' doesn't match value 'MD_DynamicRelease'

I see the document RuntimeLibrary part and then I don’t know what can I do.
https://docs.microsoft.com/en-us/previous-versions/jj889284(v=vs.140)?redirectedfrom=MSDN

libcpmt.lib(StlCompareStringA.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Groupsock.cpp.obj libcpmt.lib(StlLCMapStringW.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Groupsock.cpp.obj

Again, you’re mixing and matching Release and Debug runtimes. I really recommend you get everything using the same runtime.

No [s]he probably did not @ben.boeckel ,

FWIW, if [s]he did then the message would have been instead as an example (as I tested it to confirm):
Error|LNK2038|mismatch detected for ‘RuntimeLibrary’: value ‘MT_StaticRelease’ doesn’t match value ‘MTd_StaticDebug’ in …/…

What happened most probaly to @alice (as it happened to me recently while learning more about this issue) is that there is a discrepancy between vtk release build and the app cmake build.

More precisely and typically:
1- the vtk lib builds fully static and one can check it’s the case using dumpbin /all anyvtklib.obj and check that the linker links with the /LIBCMT option (search for External Linker in the dump)
2- the app does NOT build properly in static mode because cmakelist.txt flags (or the vcxproj itself if not using cmake) are not correctly configured yet even if no build mixing can happen (because we only use release builds for example).

@alice Assuming you are using cmake for your app that links with VTK, if you just added these in your cmake file it should now work:
add_compile_options(“/MT$<$CONFIG:Debug:d>”)

Then for each app or lib, add:
set_property(TARGET MyAppNameUsingVTK PROPERTY
MSVC_RUNTIME_LIBRARY “MultiThreaded$<$CONFIG:Debug:Debug>”)

If you use directly your own vcxproj solution file, then just go to compiler/code generation and change /MD to /MT (not discussing debug cases here to keep it simple).

Also note that for more recent cmake versions, the best resolution i found if you are using cmake is:

  1. Use the CMP0091 policy setting to be able to use the MSVC option in point 2 like this :slight_smile:
if(POLICY CMP0091)
  cmake_policy(SET CMP0091 NEW) 
endif()
  1. Then only add the new property definition:
    set_property(TARGET MyVtkAppOrLibName PROPERTY
        MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

for each project it links to,

Note that once the CMP if section is inserted in step 1, we don’t need to set manually the /MP flag , the old cmake way (as it can cause other problems).