Microsoft made std::mutex constexpr in the STL for VS17.10 and later

If you try to build OpenCV 4 or 5 Release with Visual Studio 17.10 or later with dynamic C runtime, it will die on the first attempt to use a mutex (which will be during trace initialization, or logging initialization if you have trace disabled).

The only workarounds are:

  1. Build it in Debug
  2. Build it with static runtime (/MT)
  3. Add the _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR preprocessor

It’s possible that this isn’t necessary if you aren’t using the Java bindings, but I promise one of these 3 is necessary if you are.

I think it would be very neighborly to add the _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR preprocessor definition when CMake detects this scenario.

I probably posted this wrong, but this knowledge came at a heavy price, and I really wish I had known earlier.

I’d recommend that you post this as an issue on OpenCV’s github. Then the core developers can have a look.