简体   繁体   中英

CMake+OpenCL+CUDA -> runtime library may be hidden

I'm using CMake 3.16, with a CMakeLists.txt file specifying a minimum CMake version of 3.9. In my file, I have:

find_package(CUDA 8.0 REQUIRED)
find_package(OpenCL REQUIRED)
# etc. etc.
target_link_libraries(my_executable
    PRIVATE
    cuda # The NVIDIA CUDA driver API
    ${CUDA_LIBRARIES}
    OpenCL::OpenCL
    )

Now, in the CMake generation phase, I get the error:


 CMake Warning at CMakeLists.txt:44 (add_executable):
   Cannot generate a safe runtime search path for target my_executable because
   files in some directories may conflict with libraries in implicit
   directories:

     runtime library [libOpenCL.so.1] in /usr/lib64 may be hidden by files in:
       /usr/local/cuda/lib64

   Some of these libraries may not be found correctly.

Now, I do want the libOpenCL.so.1 from the CUDA directories; and building does produce an executable with the correct dependency. How can I tell CMake that this masking is ok, and not have it print the warning message?

Note: Working with CUDA in CMake has changed a lot over the 3.x series of releases. So whatever was happening before 3.8 is irrelevant, and also things changed significantly in 3.17 with a few more non-trivial changes afterwards. Answers about pre-3.8 and 3.17-or-later are, well, fine - but not what I need.

I know this doesn't answer your question precisely , but as of CMake 3.17+, the CUDA OpenCL libraries are loaded by the FindCUDAToolkit module. It is used like so:

cmake_minimum_required(VERSION 3.17)
project(my_proj LANGUAGES C CXX CUDA)

find_package(CUDAToolkit 8.0 REQUIRED)

# ...

target_link_libraries(
  my_executable
  PRIVATE
    CUDA::cuda_driver
    CUDA::cudart
    CUDA::OpenCL
)

I hope this answer will help other readers who are using up-to-date CMake, because whatever answer works on 3.9 will not be quite as nice.

As @AlexReinking suggests in a comment, you can avoid this warning by giving CMake a (strong) hint regarding which OpenCL location you want to use. Before running CMake, set your OpenCL_ROOT environment variable to /usr/local/cuda ; with a CMake version higher than 3.12, the find_package() command will use that variable, preferring to locate OpenCL there if possible - and not warn you about the alternative location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM