CMake incorrectly links to nvrtc-builtins

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, 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!

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

CC: @robert.maynard

It’s the latest release, 3.30.4.

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

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.

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.

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