# FindCUDAToolkit unable to find cudart library

**URL:** https://discourse.cmake.org/t/findcudatoolkit-unable-to-find-cudart-library/5406
**Category:** Code
**Tags:** os:linux, lang:cuda
**Created:** [April 8, 2022, 1:55am UTC](https://discourse.cmake.org/t/findcudatoolkit-unable-to-find-cudart-library/5406 "2022-04-08T01:55:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![naglemi](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/ac91a4/32.png) [@naglemi](https://discourse.cmake.org/u/naglemi)
#### Post date: [April 8, 2022, 1:55am UTC](https://discourse.cmake.org/t/findcudatoolkit-unable-to-find-cudart-library/5406/1 "2022-04-08T01:55:41Z")

</div>

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:

```auto
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)
  CMakeModules/FindNVML.cmake:66 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  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](https://stackoverflow.com/questions/51756562/obtaining-the-cuda-include-dir-in-c-targets-with-native-cuda-support-cmake)).

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

```auto
find_package(CUDAToolkit)
add_executable(
    binary_linking_to_cudart 
    my_cpp_file_using_cudart.cpp
)
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:

```auto
-- 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
  "10.1.243")
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?

```auto
(snpint) gmobot@forestry-rda-p5820-ubuntu:~/snpint-gpu$ sudo find / -name libcudart.*
/home/gmobot/anaconda3/pkgs/cudatoolkit-11.0.221-h6bb024c_0/lib/libcudart.so.11.0.221
/home/gmobot/anaconda3/pkgs/cudatoolkit-11.0.221-h6bb024c_0/lib/libcudart.so.11.0
/home/gmobot/anaconda3/pkgs/cudatoolkit-11.0.221-h6bb024c_0/lib/libcudart.so
/usr/lib/x86_64-linux-gnu/libcudart.so.10.1.243
/usr/lib/x86_64-linux-gnu/libcudart.so.10.1
/usr/lib/x86_64-linux-gnu/libcudart.so
/usr/share/man/man7/libcudart.7.gz
/usr/share/man/man7/libcudart.so.7.gz

```

Thanks for your time and help!

---

<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 9, 2022, 12:57pm UTC](https://discourse.cmake.org/t/findcudatoolkit-unable-to-find-cudart-library/5406/2 "2022-04-09T12:57:09Z")

</div>

@robert.maynard

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [April 11, 2022, 1:29pm UTC](https://discourse.cmake.org/t/findcudatoolkit-unable-to-find-cudart-library/5406/3 "2022-04-11T13:29:19Z")

</div>

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.
