# How does one link against CUDA "compatibility libs"

**URL:** https://discourse.cmake.org/t/how-does-one-link-against-cuda-compatibility-libs/1467
**Category:** Code
**Created:** [June 30, 2020, 7:40pm UTC](https://discourse.cmake.org/t/how-does-one-link-against-cuda-compatibility-libs/1467 "2020-06-30T19:40:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![paterno](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@paterno](https://discourse.cmake.org/u/paterno)
#### Post date: [June 30, 2020, 7:40pm UTC](https://discourse.cmake.org/t/how-does-one-link-against-cuda-compatibility-libs/1467/1 "2020-06-30T19:40:46Z")

</div>

I am using CMake v3.18.0rc2 to build a CUDA program that uses CUDA 11, on Scientific Linux 7 (a CentOS-7 relative). The drivers for CUDA 11 are not available on CentOS-7 (they are for CentOS-8), so I have been advised to link against the “compatibility libraries” in /usr/local/cuda-11.0/compat. I have not been able to find documentation on how to do this using CMake.

The CMakeLists.txt fragment responsible for generating this executable is:

```auto
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
project(cudaCuhre LANGUAGES CUDA CXX)
enable_testing()
find_package(MPI REQUIRED)
find_package(OpenMP REQUIRED)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)

add_executable(test_cuhre_convergence test_cuhre_convergence.cu)
set_property(TARGET test_cuhre_convergence PROPERTY CUDA_ARCHITECTURES 70-real)
#target_compile_options(test_cuhre_convergence PRIVATE "-arch=sm_70")
set_target_properties(test_cuhre_convergence PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(test_cuhre_convergence util ${MPI_CXX_LIBRARIES} ${OpenMP_CXX_LIBRARIES} testmain)
target_include_directories(test_cuhre_convergence PRIVATE
  ${CMAKE_SOURCE_DIR}
  ${CMAKE_SOURCE_DIR}/externals
)
add_test(test_cuhre_convergence test_cuhre_convergence)

```

This generates a makefile that builds an executable, but the executable is not linked to the compatibility libraries mentioned, and so the executable fails at runtime with a complaint:

```auto
CUDA driver version is insufficient for CUDA runtime version

```

---

<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: [July 1, 2020, 1:14pm UTC](https://discourse.cmake.org/t/how-does-one-link-against-cuda-compatibility-libs/1467/2 "2020-07-01T13:14:29Z")

</div>

CMake extracts the cuda runtime and driver information from the compiler when it builds a test executable.

It would best to post the compile and link line(s) of your project. I expect that the compiler you are using is not picking up the correct compat libraries.

---

<div class="post-metadata">

### Author: ![paterno](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@paterno](https://discourse.cmake.org/u/paterno)
#### Post date: [July 1, 2020, 2:10pm UTC](https://discourse.cmake.org/t/how-does-one-link-against-cuda-compatibility-libs/1467/3 "2020-07-01T14:10:28Z")

</div>

A suggestion from someone at Nvidia solved the problem: it is nothing to do with CMake.  
Putting the directory ` /usr/local/cuda-11.0/compat` before `/usr/local/cuda-11.1/lib64` in `LD_LIBRARY_PATH` fixes the problem.
