Does opencv compiles on Windows?

No matter what, which ever compiler I use, it does not compile on Windows?
Has anyone compiled the latest 4.5.3 on windows, and what are the flags and compiler.
I had visual studio 2017 and Visual Studio 2019, and tried with older mingw and the latest mingw x86_64-8.1.0-posix-seh-rt_v6-rev0, but it always give one error or another.

Sorry looks like CMake Issue, it does not take the compiler specified but mixes different compilers. I renamed all the other compilers folder names and then it compiled with VS 2019

1 Like

See if somebody online has compiled OpenCV for Windows already. What version of Windows are you using?

there are official binary releases on Releases - OpenCV

I configure and compile on windows well. You need indeed VS2019, cmake installed and in the $env:path variables starting with $ such as $src are variables defined in a powershell script.

For instance:

$solution = "OpenCV.sln"
$base = "I:/src/opencv-4.5.3"
$src = $base + "/opencv"
$srcextra = $base + "/opencv_contrib/modules"
$builddir = $base + "/build"
$target = "Visual Studio 16 2019"
$distname = "v453_vtk903_cuda114"

$env: are environement variables, eg., $env:CUDNN where CUDNN equals C:\lib\cudnn-11.4-x64-v8.2.2.26

To configure (with a certain configuration, feel free to edit yourself):

cmake -G $target -A x64 -S $src `
        -DBUILD_JAVA=0 -DWITH_MATLAB=0 -DBUILD_DOC=0 -DBUILD_PERF_TESTS=0 -DBUILD_TESTS=0 -DBUILD_opencv_world=1 `
        -DOPENCV_ENABLE_NONFREE=1 -DBUILD_opencv-apps=0 -DENABLE_PYLINT=0 -DENABLE_CXX11=1 `
        -DVTK_DIR="$Env:VTK_DIR" -DWITH_VTK=0 -DBUILD_opencv_viz=0 -DCPU_BASELINE=AVX2 `
        -DCUDA_SDK_ROOT_DIR="$env:CUDA_PATH" -DCUDA_ARCH_BIN="7.5" -DCUDA_ARCH_PTX="7.5" -DCUDA_VERBOSE_BUILD=1 -DBUILD_CUDA_STUBS=0 `
        -DWITH_OPENCL=0 -DWITH_CUDA=1 -DMKL_WITH_OPENMP=0 -DCUDA_NVCC_FLAGS="-t 20" -DMKL_WITH_TBB=0 -DWITH_TBB=1 `
        -DTBB_DIR="$Env:TBB_DIR" -DTBB_ENV_INCLUDE="$Env:TBB_INCLUDE_DIR" -DTBB_ENV_LIB="$Env:TBB_LIB_DIR" `
        -DOPENCV_EXTRA_MODULES_PATH="$srcextra" -DPYTHON2_EXECUTABLE="C:\Python27\python.exe" `
        -DINSTALL_CREATE_DISTRIB=1 -DCPACK_BINARY_ZIP=1 -DCPACK_SOURCE_ZIP=1 -DCMAKE_VERBOSE_MAKEFILE=0 `
        -DCUDNN_INCLUDE_DIR="$Env:CUDNN"/include -DCUDNN_LIBRARY="$Env:CUDNN"/lib/x64/cudnn.lib `
        ..

To build, rebuild, install, I use those:


        MSBuild.exe /m $solution /verbosity:m
        MSBuild.exe /m $solution /p:Configuration=Release /verbosity:m

        MSBuild.exe /m /t:Rebuild $solution /verbosity:m
        MSBuild.exe /m /t:Rebuild $solution /p:Configuration=Release /verbosity:m

        MSBuild.exe /m INSTALL.vcxproj /verbosity:m
        MSBuild.exe /m INSTALL.vcxproj /p:Configuration=Release /verbosity:m /m