Force JUCE app to compile with MT_StaticRelease MSVC runtime

I’m in the process of getting a JUCE app to link against the essentia library.

What seems like the penultimate hoop I need to jump through is linking against a pre-compiled static lib which is linked against the MT_StaticRelease flavour of the Windows runtime.

There is a crash happening on start up which I need to debug, but I am only able to run the release build.

I think I need to force the app to build against the the same Windows runtime as the static lib I’m linking against.

I am calling this in my top-level CMakeLists (note, without the debug bits)


However I still get this error

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

I then noticed this in the JUCE CMake internals:

    set_target_properties(juceaide PROPERTIES
        MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

However removing the debug parts here did not fix the error.

@reuk ?

This will only affect juceaide, so it’s probably unrelated to the issue you’re seeing.

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

Assuming that Window.obj is the object file generated from your own file named Window.cpp, it sounds like the CMAKE_MSVC_RUNTIME_LIBRARY option isn’t having an effect.

I’d suggest checking where set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded") is called, and moving it so that it is called as early as possible. If you’re pulling in other dependencies, maybe try printing/debugging the value of CMAKE_MSVC_RUNTIME_LIBRARY at various points to check that none of those are forcefully overriding this option. Finally, you could try setting the MSVC_RUNTIME_LIBRARY property directly on your target. You can also use get_target_property to query this value.

It may help to remove and recreate your build folder, just to be sure that new object files have been generated.

1 Like


I’d already tried setting it directly on the target with

set_property(TARGET foo PROPERTY
  MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

I’ve now placed this in various places in my CMakeLists:

message(STATUS "Runtime library: ${RUNTIME_LIB}")

and it tells me -- Runtime library: MultiThreaded in each place.

Uisng RelWithDebugInfo solved my problem :slight_smile: