# Unable to Compile OpenCV with CUDA support on Ubuntu 22.04

**URL:** <https://forum.opencv.org/t/unable-to-compile-opencv-with-cuda-support-on-ubuntu-22-04/18389>\
**Category:** Uncategorized\
**Tags:** dnn, build, cuda\
**Created:** [July 31, 2024, 7:06pm UTC](https://forum.opencv.org/t/unable-to-compile-opencv-with-cuda-support-on-ubuntu-22-04/18389 "2024-07-31T19:06:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![crookedegg](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@crookedegg](https://forum.opencv.org/u/crookedegg)\
**Post date:** [July 31, 2024, 7:06pm UTC](https://forum.opencv.org/t/unable-to-compile-opencv-with-cuda-support-on-ubuntu-22-04/18389/1 "2024-07-31T19:06:17Z")

</div>

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-smi`suggested 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](https://docs.google.com/document/d/1oGOqQHntowQTdKnOzRhoceFqUOJCVKBv-8hndLVnnaI/edit?usp=sharing)  
[Compilation results](https://docs.google.com/document/d/1Hh2MshZhquihD8Ru1Q20k92sPswjCYg05apC3gTycrs/edit?usp=sharing)

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

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [July 31, 2024, 7:19pm UTC](https://forum.opencv.org/t/unable-to-compile-opencv-with-cuda-support-on-ubuntu-22-04/18389/2 "2024-07-31T19:19:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![crookedegg](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@crookedegg](https://forum.opencv.org/u/crookedegg)\
**Post date:** [July 31, 2024, 7:53pm UTC](https://forum.opencv.org/t/unable-to-compile-opencv-with-cuda-support-on-ubuntu-22-04/18389/3 "2024-07-31T19:53:33Z")

</div>

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