# CMake incorrectly links to nvrtc-builtins

**URL:** <https://discourse.cmake.org/t/cmake-incorrectly-links-to-nvrtc-builtins/12723>\
**Category:** Code\
**Tags:** os:linux, lang:cuda\
**Created:** [October 8, 2024, 8:45pm UTC](https://discourse.cmake.org/t/cmake-incorrectly-links-to-nvrtc-builtins/12723 "2024-10-08T20:45:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![peastman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/peastman/32/5007_2.png) [@peastman](https://discourse.cmake.org/u/peastman)\
**Post date:** [October 8, 2024, 8:45pm UTC](https://discourse.cmake.org/t/cmake-incorrectly-links-to-nvrtc-builtins/12723/1 "2024-10-08T20:45:01Z")

</div>

I have a program that uses CUDA, and more specifically the nvrtc runtime compiler. In my build script, I call `find_package(CUDAToolkit)`, then use `target_link_libraries()` to link to `CUDA::nvrtc`.

It is supposed to be binary compatible across minor versions. Its SONAME is, for example, `libnvrtc.so.12`. You can compile against any 12.x version, then run with any other 12.x version.

There’s another library called `libnvrtc-builtins` which does not work that way. Its SONAME is, for example, `libnvrtc-builtins.so.12.6`. Linking to it would break binary compatibility. However, you are never supposed to link to it directly. According to [the CUDA documentation](https://docs.nvidia.com/cuda/nvrtc/index.html#nvrtc-builtins-library), it is only for internal use by the nvrtc library.

When I compile against CUDA 11 this works as expected. I can compile against 11.8 and it works equally well with 11.7. But when I compile against CUDA 12, I find that CMake is incorrectly linking in `nvrtc-builtins`. That breaks binary compatibility. If I compile against CUDA 12.5, my program can only be used with that exact version, not 12.4 or 12.6.

How can I prevent CMake from incorrectly linking my code to `nvrtc-builtins`?

Thanks!

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [October 8, 2024, 9:36pm UTC](https://discourse.cmake.org/t/cmake-incorrectly-links-to-nvrtc-builtins/12723/2 "2024-10-08T21:36:22Z")

</div>

What CMake version are you using? If you haven’t already, please try the latest release.

CC: @robert.maynard

---

<div class="post-metadata">

**Author:** ![peastman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/peastman/32/5007_2.png) [@peastman](https://discourse.cmake.org/u/peastman)\
**Post date:** [October 8, 2024, 10:13pm UTC](https://discourse.cmake.org/t/cmake-incorrectly-links-to-nvrtc-builtins/12723/3 "2024-10-08T22:13:44Z")

</div>

It’s the latest release, 3.30.4.

---

<div class="post-metadata">

**Author:** ![peastman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/peastman/32/5007_2.png) [@peastman](https://discourse.cmake.org/u/peastman)\
**Post date:** [October 8, 2024, 10:57pm UTC](https://discourse.cmake.org/t/cmake-incorrectly-links-to-nvrtc-builtins/12723/4 "2024-10-08T22:57:55Z")

</div>

I think I’ve found a way to work around the problem:

```auto
FIND_LIBRARY(NVRTC_LIB nvrtc PATHS "${CUDAToolkit_LIBRARY_DIR}")

```

and then I link to `${NVRTC_LIB}` instead of `CUDA::nvrtc`. I still need to test a bit more, but so far it seems to be working.

---

<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:** [October 9, 2024, 3:44pm UTC](https://discourse.cmake.org/t/cmake-incorrectly-links-to-nvrtc-builtins/12723/5 "2024-10-09T15:44:39Z")

</div>

Thanks for reporting this. Looking at it more and I believe the issue was that I naively assumed that the libnvrtc.so dependency matched that of libnvrtc\_static.a. The static libraries have unresolved symbols from libnvrtc-builtin, but the shared library doesn’t ( it has those symbols included inside of it ).

I will open a CMake PR to correct this.

---

<div class="post-metadata">

**Author:** ![peastman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/peastman/32/5007_2.png) [@peastman](https://discourse.cmake.org/u/peastman)\
**Post date:** [October 9, 2024, 3:51pm UTC](https://discourse.cmake.org/t/cmake-incorrectly-links-to-nvrtc-builtins/12723/6 "2024-10-09T15:51:26Z")

</div>

Thanks, that will be great! In the mean time, I can use the workaround.
