Repository: opencv
Issue: Unable to build openCV on Windows
Labels: bug,feature,category: build/install

### System Information

Windows version:
```
Edition	Windows 11 Home
Version	23H2
Installed on	‎2/‎17/‎2024
OS build	22635.4076
Experience	Windows Feature Experience Pack 1000.22700.1036.0
```
VS version:
```
17.12.0 Preview 1.0
```
Clang version:
```
clang version 20.0.0git (https://github.com/llvm/llvm-project.git 4db37a49a72bb9cff7a78e77439008c058383099)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Users\rysza\bin\LLVM\bin
```
Intel OneAPI base toolkit version:
```
2024.2
```
Python version:
```
Python 3.12.5
```
CMake configuration reported after configuring:
```
--
-- General configuration for OpenCV 4.10.0-dev =====================================
--   Version control:               4d66541
--
--   Platform:
--     Timestamp:                   2024-09-01T16:56:19Z
--     Host:                        Windows 10.0.22635 AMD64
--     CMake:                       3.29.5-msvc4
--     CMake generator:             Ninja
--     CMake build tool:            C:/ProgramData/chocolatey/bin/ninja.exe
--     MSVC:                        1942
--     Configuration:               Release
--     Algorithm Hint:              ALGO_HINT_ACCURATE
--
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3 SSSE3 SSE4_1 POPCNT SSE4_2 AVX FP16 AVX2 FMA3
--       requested:                 AVX2
--     Dispatched code generation:  AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       AVX512_SKX (8 files):      + AVX_512F AVX512_COMMON AVX512_SKX
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                C:/Users/rysza/bin/LLVM/bin/clang-cl.exe  (ver 20.0.0)
--     C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise -W -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -Wno-long-long -Qunused-arguments /FS  -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mavx2 -mfma /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819  /O2 /Ob2 /DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise -W -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -Wno-long-long -Qunused-arguments /FS  -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mavx2 -mfma /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819  /Zi /Ob0 /Od /RTC1  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  C:/Users/rysza/bin/LLVM/bin/clang-cl.exe
--     C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise -W -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -Wno-long-long -Qunused-arguments /FS  -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mavx2 -mfma   /O2 /Ob2 /DNDEBUG  -DNDEBUG
--     C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise -W -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -Wno-long-long -Qunused-arguments /FS  -msse3 -mssse3 -msse4.1 -mpopcnt -msse4.2 -mavx -mf16c -mavx2 -mfma /Zi /Ob0 /Od /RTC1  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      /machine:x64  /INCREMENTAL:NO
--     Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL
--     ccache:                      YES
--     Precompiled headers:         NO
--     Extra dependencies:
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc java ml objdetect photo python3 stitching ts video videoio
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 python2
--     Applications:                tests perf_tests examples apps
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   Windows RT support:            NO
--
--   GUI:                           WIN32UI
--     Win32 UI:                    YES
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        build (ver 1.3.1)
--     JPEG:                        build-libjpeg-turbo (ver 3.0.3-70)
--       SIMD Support Request:      YES
--       SIMD Support:              YES
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.43)
--       SIMD Support Request:      YES
--       SIMD Support:              YES (Intel SSE)
--     TIFF:                        build (ver 42 - 4.6.0)
--     JPEG 2000:                   build (ver 2.5.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     FFMPEG:                      YES (prebuilt binaries)
--       avcodec:                   YES (58.134.100)
--       avformat:                  YES (58.76.100)
--       avutil:                    YES (56.70.100)
--       swscale:                   YES (5.9.100)
--       avresample:                YES (4.0.0)
--     GStreamer:                   NO
--     DirectShow:                  YES
--     Media Foundation:            YES
--       DXVA:                      YES
--
--   Parallel framework:            TBB (ver 2021.13 interface 12130)
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Intel IPP:                   2021.12.0 [2021.12.0]
--            at:                   C:/Users/rysza/lib/opencv/build/3rdparty/ippicv/ippicv_win/icv
--     Intel IPP IW:                sources (2021.12.0)
--               at:                C:/Users/rysza/lib/opencv/build/3rdparty/ippicv/ippicv_win/iw
--     Lapack:                      YES (C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_intel_lp64.lib C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_sequential.lib C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_core.lib)
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--     Flatbuffers:                 builtin/3rdparty (23.5.9)
--
--   OpenCL:                        YES (NVD3D11)
--     Include path:                C:/Users/rysza/lib/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 3:
--     Interpreter:                 C:/Python312/python.exe (ver 3.12.5)
--     Libraries:                   C:/Python312/libs/python312.lib (ver 3.12.5)
--     Limited API:                 NO
--     numpy:                       C:/Python312/Lib/site-packages/numpy/core/include (ver 1.26.4)
--     install path:                C:/Python312/Lib/site-packages/cv2/python-3.12
--
--   Python (for build):            C:/Python312/python.exe
--
--   Java:
--     ant:                         NO
--     Java:                        YES (ver 21.0.4)
--     JNI:                         C:/Program Files/Eclipse Adoptium/jdk-21.0.4.7-hotspot/include C:/Program Files/Eclipse Adoptium/jdk-21.0.4.7-hotspot/include/win32 C:/Program Files/Eclipse Adoptium/jdk-21.0.4.7-hotspot/include
--     Java wrappers:               YES (JAVA)
--     Java tests:                  NO
--
--   Install to:                    C:/Users/rysza/local
-- -----------------------------------------------------------------
--
-- Configuring done (152.7s)
-- Generating done (1.8s)
-- Build files have been written to: C:/Users/rysza/lib/opencv/build
```

### Detailed description

When building with cmake + Ninja and clang-cl at some point the build freezes with broken stdout. If I terminate with ctrl-c and start again with cmake I get stuck on linking opencv_core4100.dll. This is not because it is slow. It gets stuck for multiple hours, with high CPU usage but basically no memory usage, maybe 400MB. Tried with both ENABLE_LTO and ENABLE_THIN_LTO. Here is a screenshot of it. 
![image](https://github.com/user-attachments/assets/ca086416-957b-4d45-bb43-8b27dcf69abb)


### Steps to reproduce

Building with this cmake command:
```
cmake -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_LINKER=lld-link 
-DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_INSTALL_PREFIX=C:/Users/rysza/local 
-DCPU_BASELINE:STRING=AVX2 -DOPENCV_IP_ENABLE_ALL=ON -DWITH_TBB=ON 
-DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DBUILD_EXAMPLES=ON
```
and 
```
cmake --build build
```

### Issue submission checklist

- [X] I report the issue, it's not a question
- [X] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [X] I updated to the latest OpenCV version and the issue is still there
- [X] There is reproducer code and related data files (videos, images, onnx, etc)