Can't build OpenCV with CUDA support

Made a lot of efforts with different parameters to build the OpenCV with CUDA support but everytime got the error:

FAILED: bin/opencv_world490.dll lib/opencv_world490.lib
C:\windows\system32\cmd.exe /C “cd . && “C:\Program Files\CMake\bin\cmake.exe” -E vs_link_dll --intdir=modules\world\CMakeFiles\opencv_world.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\mt.exe --manifests – C:\PROGRA~1\MIB055~1\2022\PROFES~1\VC\Tools\MSVC\1438~1.331\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\opencv_world.rsp /out:bin\opencv_world490.dll /implib:lib\opencv_world490.lib /pdb:bin\opencv_world490.pdb /dll /version:4.9 /machine:x64 /INCREMENTAL:NO /NODEFAULTLIB:libc /DEBUG && cd .” LINK: command “C:\PROGRA~1\MIB055~1\2022\PROFES~1\VC\Tools\MSVC\1438~1.331\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\opencv_world.rsp /out:bin\opencv_world490.dll /implib:lib\opencv_world490.lib /pdb:bin\opencv_world490.pdb /dll /version:4.9 /machine:x64 /INCREMENTAL:NO /NODEFAULTLIB:libc /DEBUG /MANIFEST:EMBED,ID=2” failed (exit code 1181) with the following output:
LINK : fatal error LNK1181: cannot open input file ‘x64.lib’

I use manual from this link: https://www.jamesbowley.co.uk/qmd/opencv_cuda_python_windows.html Tried to build with Visual Studio 2019, 2022, Ninja. Made efforts with different versions of OpenCV. But no effect

Build files configuring and generating done with this data:

-- General configuration for OpenCV 4.9.0 =====================================
--   Version control:               unknown
--
--   Extra modules:
--     Location (extra):            C:/opencv/opencv_contrib-4.9.0/modules
--     Version control (extra):     unknown
--
--   Platform:
--     Timestamp:                   2024-01-07T09:01:30Z
--     Host:                        Windows 10.0.22621 AMD64
--     CMake:                       3.28.1
--     CMake generator:             Ninja
--     CMake build tool:            C:/PROGRA~2/MICROS~2/2019/PROFES~1/Common7/IDE/COMMON~1/MICROS~1/CMake/Ninja/ninja.exe
--     MSVC:                        1929
--     Configuration:               Release
--
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (18 files):         + SSSE3 SSE4_1
--       SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (9 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (38 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe  (ver 19.29.30153.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 /FS     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819  /O2 /Ob2 /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 /FS     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819  /Zi /Ob0 /Od /RTC1
--     C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/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 /FS       /O2 /Ob2 /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 /FS     /Zi /Ob0 /Od /RTC1
--     Linker flags (Release):      /machine:x64  /INCREMENTAL:NO
--     Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib x64 cufft.lib -LIBPATH:"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1/lib/x64" -LIBPATH:"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDNN/v8.9.6.50/lib"
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode world xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    -
--     Disabled by dependency:      -
--     Unavailable:                 alphamat cannops cvv freetype hdf java julia matlab ovis python2 python2 sfm viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   Windows RT support:            NO
--
--   GUI:
--     Win32 UI:                    YES
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        build (ver 1.3)
--     JPEG:                        build-libjpeg-turbo (ver 2.1.3-62)
--       SIMD Support Request:      YES
--       SIMD Support:              NO
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.37)
--     TIFF:                        build (ver 42 - 4.2.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:
--     DC1394:                      NO
--     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:            Concurrency
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Intel IPP:                   2021.11.0 [2021.11.0]
--            at:                   C:/opencv/build/3rdparty/ippicv/ippicv_win/icv
--     Intel IPP IW:                sources (2021.11.0)
--               at:                C:/opencv/build/3rdparty/ippicv/ippicv_win/iw
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--     Flatbuffers:                 builtin/3rdparty (23.5.9)
--
--   NVIDIA CUDA:                   YES (ver 12.1, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             61 70 80 86 89 90
--     NVIDIA PTX archs:            90
--
--   cuDNN:                         YES (ver 8.9.6)
--
--   OpenCL:                        YES (NVD3D11)
--     Include path:                C:/opencv/opencv-4.9.0/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 3:
--     Interpreter:                 C:/ProgramData/anaconda3/python.exe (ver 3.11.5)
--     Libraries:                   C:/ProgramData/anaconda3/libs/python311.lib (ver 3.11.5)
--     numpy:                       C:/ProgramData/anaconda3/Lib/site-packages/numpy/core/include (ver 1.24.3)
--     install path:                C:/ProgramData/anaconda3/Lib/site-packages/cv2/python-3.11
--
--   Python (for build):            C:/ProgramData/anaconda3/python.exe
--
--   Java:
--     ant:                         NO
--     Java:                        NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    C:/opencv/build/install
-- -----------------------------------------------------------------
--
-- Configuring done (12.0s)
-- Generating done (7.6s)

Can’t understand what the reason of the issue and how to solve it.

Can you share your exact cmake input args and I’ll take a look tomorrow with CMake 3.28.1.

x64 inside your extra dependencies is causing the issue.

I suspect it could be a result of the arguments you pass to CMake. I also notice that you have

are you manually passing the location to CMake or is it installed?

I found the reason of problem. It was really a result of the arguments I passed to CMAKE. The specification of -DCUDNN_LIBRARY argument as:

-DCUDNN_LIBRARY="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDNN\v8.9.6.50\lib\x64\cudnn.lib"

solved the problem.

Thank you for your advice.

That’s great. By the way you don’t need to specify -DCUDNN_LIBRARY if you have installed it.

1 Like