title: CMAKE in my OpenCV 4.2.0 source code couldn't find any cuDNN installed in my machine
body: <p>I'm compiling OpenCV4.2 on Ubuntu 20.4 following this tutorial <a href="https://www.pyimagesearch.com/2020/02/03/how-to-use-opencvs-dnn-module-with-nvidia-gpus-cuda-and-cudnn/" rel="nofollow noreferrer">https://www.pyimagesearch.com/2020/02/03/how-to-use-opencvs-dnn-module-with-nvidia-gpus-cuda-and-cudnn/</a></p>
  <p>I did make sure to download cudnn-11.2-linux-x64-v8.1.0.77.tgz for my CUDA 11.2, extract it, and copy all the files to the appropriate folders in /usr/local/cuda/lib64 and /usr/local/cuda/include</p>
  <p>I run CMAKE in the /build folder of opencv source code like this:</p>
  <pre><code>cmake -D CMAKE_BUILD_TYPE=RELEASE \
  -D CMAKE_INSTALL_PREFIX=/usr/local \
  -D INSTALL_PYTHON_EXAMPLES=ON \
  -D INSTALL_C_EXAMPLES=OFF \
  -D OPENCV_ENABLE_NONFREE=ON \
  -D WITH_CUDA=ON \
  -D WITH_CUDNN=ON \
  -D OPENCV_DNN_CUDA=ON \
  -D ENABLE_FAST_MATH=1 \
  -D CUDA_FAST_MATH=1 \
  -D CUDA_ARCH_BIN=5.0 \
  -D WITH_CUBLAS=1 \
  -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
  -D HAVE_opencv_python3=ON \
  -D PYTHON_EXECUTABLE=~/.virtualenvs/opencv_cuda/bin/python \
  -D BUILD_EXAMPLES=ON \
  -D CUDNN_LIBRARY=/usr/local/cuda/lib64/ \
  -D CUDNN_INCLUDE_DIR=/usr/local/cuda/include ..
  </code></pre>
  <p>However the output log of CMAKE shows cuDNN is NO, this is the snippet of the errors:</p>
  <pre><code>-- Could NOT find CUDNN: Found unsuitable version &quot;..&quot;, but required is at least &quot;7.5&quot; (found /usr/local/cuda/lib64/libcudnn.so)
  -- CUDA detected: 11.2
  -- CUDA NVCC target flags: -gencode;arch=compute_50,code=sm_50;-D_FORCE_INLINES
  </code></pre>
  <p>And here is the full configuration output</p>
  <blockquote>
  <pre><code>- General configuration for OpenCV 4.2.0 =====================================
  --   Version control:               unknown
  -- 
  --   Extra modules:
  --     Location (extra):            /home/thomasm/opencv_contrib_self_built/modules
  --     Version control (extra):     unknown
  -- 
  --   Platform:
  --     Timestamp:                   2021-02-16T15:54:14Z
  --     Host:                        Linux 5.8.0-43-generic x86_64
  --     CMake:                       3.16.3
  --     CMake generator:             Unix Makefiles
  --     CMake build tool:            /usr/bin/make
  --     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 (16 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 (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
  --       AVX2 (29 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
  --       AVX512_SKX (6 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++ Compiler:                /usr/bin/c++  (ver 9.3.0)
  --     C++ flags (Release):         -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
  --     C++ flags (Debug):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
  --     C Compiler:                  /usr/bin/cc
  --     C flags (Release):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
  --     C flags (Debug):             -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
  --     Linker flags (Release):      -Wl,--gc-sections  
  --     Linker flags (Debug):        -Wl,--gc-sections  
  --     ccache:                      NO
  --     Precompiled headers:         NO
  --     Extra dependencies:          m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cufft -L/usr/lib/x86_64-linux-gnu
  --     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 freetype fuzzy gapi hdf hfs highgui img_hash
       imgcodecs imgproc line_descriptor ml objdetect optflow
      phase_unwrapping photo plot python3 quality reg rgbd saliency shape
   stereo stitching structured_light superres surface_matching text
      tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect
     xphoto
  --     Disabled:                    world
  --     Disabled by dependency:      -
  --     Unavailable:                 cnn_3dobj cvv java js matlab ovis python2 sfm viz
  --     Applications:                tests perf_tests examples apps
  --     Documentation:               NO
  --     Non-free algorithms:         YES
  -- 
  --   GUI: 
  --     GTK+:                        YES (ver 3.24.20)
  --       GThread :                  YES (ver 2.64.3)
  --       GtkGlExt:                  NO
  --     VTK support:                 NO
  -- 
  --   Media I/O: 
  --     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
  --     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
  --     WEBP:                        build (ver encoder: 0x020e)
  --     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
  --     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.1.0)
  --     JPEG 2000:                   build (ver 1.900.1)
  --     OpenEXR:                     build (ver 2.3.0)
  --     HDR:                         YES
  --     SUNRASTER:                   YES
  --     PXM:                         YES
  --     PFM:                         YES
  -- 
  --   Video I/O:
  --     DC1394:                      YES (2.2.5)
  --     FFMPEG:                      YES
  --       avcodec:                   YES (58.54.100)
  --       avformat:                  YES (58.29.100)
  --       avutil:                    YES (56.31.100)
  --       swscale:                   YES (5.5.100)
  --       avresample:                NO
  --     GStreamer:                   YES (1.16.2)
  --     v4l/v4l2:                    YES (linux/videodev2.h)
  -- 
  --   Parallel framework:            pthreads
  -- 
  --   Trace:                         YES (with Intel ITT)
  -- 
  --   Other third-party libraries:
  --     Intel IPP:                   2019.0.0 Gold [2019.0.0]
  --            at:                   /home/thomasm/opencv_self_built/build/3rdparty/ippicv/ippicv_lnx/icv
  --     Intel IPP IW:                sources (2019.0.0)
  --               at:                /home/thomasm/opencv_self_built/build/3rdparty/ippicv/ippicv_lnx/iw
  --     Lapack:                      NO
  --     Eigen:                       NO
  --     Custom HAL:                  NO
  --     Protobuf:                    build (3.5.1)
  -- 
  --   NVIDIA CUDA:                   YES (ver 11.2, CUFFT CUBLAS FAST_MATH)
  --     NVIDIA GPU arch:             50
  --     NVIDIA PTX archs:
  -- 
  --   cuDNN:                         NO
  -- 
  --   OpenCL:                        YES (no extra features)
  --     Include path:                /home/thomasm/opencv_self_built/3rdparty/include/opencl/1.2
  --     Link libraries:              Dynamic load
  -- 
  --   Python 3:
  --     Interpreter:                 /usr/bin/python3 (ver 3.8.5)
  --     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.8.so (ver 3.8.5)
  --     numpy:                       /home/thomasm/.local /lib/python3.8/site-packages/numpy/core/include
      (ver 1.18.5)
  --     install path:                lib/python3.8/dist-packages/cv2/python-3.8
  -- 
  --   Python (for build):            /usr/bin/python2.7
  -- 
  --   Java:                          
  --     ant:                         NO
  --     JNI:                         /usr/lib/jvm/default-java/include
    /usr/lib/jvm/default-java/include/linux
      /usr/lib/jvm/default-java/include
  --     Java wrappers:               NO
  --     Java tests:                  NO
  -- 
  --   Install to:                    /usr/local
  </code></pre>
  </blockquote>
  <p>This is frustrating since the cmake file could detect my CUDA, but couldn't find my CUDNN</p>
  <p>Is there any fix I can make since I'm sure a lot have encountered this error as well</p>