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
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).
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).
But unfortunately there is no such property, and no warning for not-predefined properties, so I had to discover my mistake through trial and error.
As far as I can tell there is no way to set this property to be transient, so I am having to fall back to using the global set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
Or once again use set_compile_options to propogate the flags to consumers.