Unable to Compile OpenCV with CUDA support on Ubuntu 22.04

I’m new to compiling libraries from source and to Cmake, and I’m unable to compile OpenCV with CUDA. I installed nvidia driver 550 as it was the recommended driver for my gpu when I ran ubuntu-drivers devices . nvidia-smisuggested installing CUDA toolkit 12.4. I’ve installed the CUDA toolkit and the corresponding cuDNN from the nvidia website.

GPU: RTX 4070
Ubuntu: 22.04
nvidia driver: 550.54.14
CUDA Version: 12.4
cuDNN Version: 9.2.1
GCC Version: 10.5.0
open-cv Version: 4.9

Here is my cmake configs:
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D WITH_TBB=ON
-D ENABLE_FAST_MATH=1
-D ENABLE_FAST_MATH=1
-D CUDA_FAST_MATH=1
-D WITH_CUBLAS=1
-D WITH_CUDA=ON
-D BUILD_opencv_cudacodec=OFF
-D WITH_CUDNN=ON
-D OPENCV_DNN_CUDA=ON
-D CUDA_ARCH_BIN=8.9
-D CMAKE_C_COMPILER=gcc-11
-D CMAKE_CXX_COMPILER=g+±11
-D WITH_V4L=ON
-D WITH_QT=OFF
-D WITH_OPENGL=ON
-D WITH_GSTREAMER=ON
-D OPENCV_GENERATE_PKGCONFIG=ON
-D OPENCV_PC_FILE_NAME=opencv.pc
-D OPENCV_ENABLE_NONFREE=ON
-D OPENCV_PYTHON3_INSTALL_PATH=~/virtualenvs/cv_opencv_cuda/lib/python3.10/site-packages
-D PYTHON_EXECUTABLE=…/…/…/virtualenvs/cv_opencv_cuda/bin/python
-D OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib-4.9.0/modules
-D INSTALL_PYTHON_EXAMPLES=OFF
-D INSTALL_C_EXAMPLES=OFF
-D BUILD_EXAMPLES=OFF …

Cmake configs and summary
Compilation results

I don’t know what went wrong and how to fix it so any help or advice would be much appreciated :frowning:

CUDA 12.4 and cuDNN 9.2.1 are not compatible with OpenCV 4.9.0. You should pull the latest commits from the 4.x branch of both repos for compatibility with the latest versions of CUDA and cuDNN.

1 Like

Solved! May your pillow be cold on both sides and may you put the usb in the right side up the first try.

1 Like