# cmake getting confused on cuda version

**URL:** <https://discourse.cmake.org/t/cmake-getting-confused-on-cuda-version/7835>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [April 5, 2023, 2:29pm UTC](https://discourse.cmake.org/t/cmake-getting-confused-on-cuda-version/7835 "2023-04-05T14:29:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rick](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/9f8e36/32.png) [@rick](https://discourse.cmake.org/u/rick)\
**Post date:** [April 5, 2023, 2:29pm UTC](https://discourse.cmake.org/t/cmake-getting-confused-on-cuda-version/7835/1 "2023-04-05T14:29:45Z")

</div>

I have the following toolchain…  
CMake(c++)(3.26.1) → OpenCV(4.6.0) → CudaToolkit(11.7) all on Ubuntu 22.04.  
when I run cmake on my CMakeList.txt I get the following error…

CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):  
Could NOT find CUDA: Found unsuitable version “11.7”, but required is exact  
version “11.5” (found /usr/local/cuda)  
Call Stack (most recent call first):  
/usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:592 (\_FPHSA\_FAILURE\_MESSAGE)  
/usr/share/cmake-3.22/Modules/FindCUDA.cmake:1264 (find\_package\_handle\_standard\_args)  
/usr/local/lib/cmake/opencv4/OpenCVConfig.cmake:86 (find\_package)  
/usr/local/lib/cmake/opencv4/OpenCVConfig.cmake:108 (find\_host\_package)  
CMakeLists.txt:18 (find\_package)

How is cmake determining that I must have cuda 11.5?

CMakeList.txt text below

# cmake for OpenCV2 Cookbook

# your opencv/build directory should be in your system PATH

# set minimum required version for cmake

cmake\_minimum\_required(VERSION 2.8)

# define the project name

set(project\_name “Sharpen”)

# set the project name

project(“${project\_name}”)

# this is a C++11 project

set(CMAKE\_CXX\_FLAGS “${CMAKE\_CXX\_FLAGS} -std=c++11”)  
set(CMAKE\_CXX\_FLAGS “${CMAKE\_CXX\_FLAGS} -g”)

# add opencv package to the project

find\_package( OpenCV REQUIRED )  
INCLUDE\_DIRECTORIES( ${OpenCV\_INCLUDE\_DIRS} .. )  
SET(OpenCV\_LIBRARIES ${OpenCV\_LIBS})

message(STATUS “OpenCV library status:”)  
message(STATUS " version: ${OpenCV\_VERSION}“)  
message(STATUS " libraries: ${OpenCV\_LIBS}”)  
message(STATUS " include path: ${OpenCV\_INCLUDE\_DIRS}")

#SET(INCLUDES ) ${CMAKE\_SOURCE\_DIR}/linedetect.h )  
#FILE(COPY $(INCLUDES) DESTINATION .)

SET (IMAGES ${CMAKE\_SOURCE\_DIR}/007.mp4 ${CMAKE\_SOURCE\_DIR}/007\_shapshot.png ${CMAKE\_SOURCE\_DIR}/RawToMp4\_snapshot.png ${CMAKE\_SOURCE\_DIR}/shapes.png)  
FILE(COPY ${IMAGES} DESTINATION .)

add\_executable( sharpen sharpen.cpp contour.cpp )  
target\_link\_libraries( sharpen ${OpenCV\_LIBS})

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [April 24, 2023, 4:25am UTC](https://discourse.cmake.org/t/cmake-getting-confused-on-cuda-version/7835/2 "2023-04-24T04:25:43Z")

</div>

OpenCV probably embeds the CUDA version it was built against and forwards that requirement in its `OpenCVConfig.cmake`. You’ll probably want to recompile that OpenCV with CUDA 11.7 first.
