FindCUDAToolkit unable to find cudart library

First, a big thank you to the developers and community. My understanding of the fundamentals of cmake is lacking, so I greatly appreciate your time and patience.

I am trying to compile a program that comes with a CMakeLists.txt used for compilation. I’m using Ubuntu 20.04 and cmake 3.22.1. When I try to compile as is, I get this error:

CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find NVML (missing: NVML_LIBRARY)
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
  CMakeLists.txt:60 (find_package)

As I understand, the solution to this error should be to use the FindCUDAToolkit package, which is included in CMake 3.17.0 onwards (described on Stack Overflow).

Thus, I have attempted to use the approach described at the above link. This involves adding the below code to CMakeLists.txt:

target_link_libraries(binary_linking_to_cudart PRIVATE CUDA::cudart)

However, this leads me to a new error that I’ve been unable to figure out:

-- Unable to find cudart library.
CMake Error at /home/gmobot/anaconda3/envs/snpint/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find CUDAToolkit (missing: CUDA_CUDART) (found version
Call Stack (most recent call first):
  /home/gmobot/anaconda3/envs/snpint/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /home/gmobot/anaconda3/envs/snpint/share/cmake-3.22/Modules/FindCUDAToolkit.cmake:814 (find_package_handle_standard_args)
  CMakeLists.txt:54 (find_package)

I’m most confused by the line where it says it can NOT find CUDAToolkit, yet finds version 10.1.243. I would appreciate a remedial lesson on what exactly this means, because as little as I know about cmake, this sounds like a contradiction to me.

I do appear to have CUDA runtime (cudart) installed. Do I need to set some flag for cmake to find it?

(snpint) gmobot@forestry-rda-p5820-ubuntu:~/snpint-gpu$ sudo find / -name libcudart.*

Thanks for your time and help!


The cudatoolkit conda package needs to be enabled/installed in your conda enviornment for CMake to find it, since you are building within a conda env.