Ensure that CMake uses static MSVC runtime library? (Windows)

I’m trying to build a JUCE app on Windows, but I keep getting linker errors like this:

error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Main.obj

Specifically when I’m trying to link a static library dependency into the app, based on the warning it looks like the app is set to use a dynamic runtime library. So far I’ve tried setting both the CMAKE_MSVC_RUNTIME_LIBRARY variable and the MSVC_RUNTIME_LIBRARY property on the app target to use the appropriate multi-threaded runtime library as described in this thread, but that same linker error still shows up. Do I need to set something more specifically with the generator or are there some other flags I need to set or something? Any help much appreciated!

Turns out that vscode had automatically added /MD to the CMAKE_CXX_FLAGS cache entry. Changed to /MT and everything works

I added

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

as the 2nd line in my top most CMakeLists.txt and then everything used static run time.

1 Like

Hmm I have the exact same thing in my top level file and I still get this, what are you using as a generator?