在最新的CMAKE中找不到CUDA_INCLUDE_DIRS

时间:2019-04-18 07:41:18

标签: cmake cuda

从CMAKE 3.10开始,默认情况下支持CUDA宏(https://cmake.org/cmake/help/latest/module/FindCUDA.html)。

但是我找不到变量CUDA_INCLUDE_DIRS

cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(cmake_and_cuda LANGUAGES CXX CUDA)

message(${CUDA_INCLUDE_DIRS})

错误是

-- The CXX compiler identification is GNU 5.4.0
-- The CUDA compiler identification is NVIDIA 10.0.130
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
CMake Error at CMakeLists.txt:7 (message):
  message called with incorrect number of arguments


-- Configuring incomplete, errors occurred!
See also "/home/tumh/code-samples/posts/cmake/build/CMakeFiles/CMakeOutput.log".

有什么主意吗?

1 个答案:

答案 0 :(得分:-1)

只需使用${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}

在所有.cu src文件中,无需手动添加

include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}),

因为CMake将为您做到这一点。

但是对于.cpp src文件,如果需要include <cuda_runtime.h>,则必须手动添加

include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) 

在您的CMakeLists.txt中。