Skip to content

FindCUDAToolkit: On Unix CUDA::cudart_static must also link with libpthread, librt (only on non-apple platforms) and libdl

Part of this logic was already on FindCUDA.cmake, but there were some missing libs. This was tested with cuda-10.2 on a linux machine:

The following should be added after find_and_add_cuda_import_lib(cudart_static):

if(UNIX AND TARGET CUDA::cudart_static)
    if(NOT APPLE)
        # On Linux, you must link against librt when using the static cuda runtime.
        find_library(CUDA_rt_LIBRARY rt)
        if(NOT CUDA_rt_LIBRARY)
            message(WARNING "Could not find librt library, needed by libcudart_static")
        else()
            target_link_libraries(CUDA::cudart_static INTERFACE ${CUDA_rt_LIBRARY})
        endif()
    endif()

    # Can't use find_package(Threads), cudart_static really requires libpthread
    find_library(CUDA_pthread_LIBRARY NAMES pthread)
    if(NOT CUDA_pthread_LIBRARY)
        message(STATUS "Could not find libpthread library, needed by libcudart_static")
    else()
       target_link_libraries(CUDA::cudart_static INTERFACE ${CUDA_pthread_LIBRARY})
    endif()

    target_link_libraries(CUDA::cudart_static INTERFACE ${CMAKE_DL_LIBS})
endif()
Edited by Brad King
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information