Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find CUDA_INCLUDE_DIRS in latest CMAKE [duplicate]

Tags:

cuda

cmake

Since in CMAKE 3.10, CUDA macro is supported by default (https://cmake.org/cmake/help/latest/module/FindCUDA.html).

But I can't find the variable CUDA_INCLUDE_DIRS

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

message(${CUDA_INCLUDE_DIRS})

the errors are

-- 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".

Any idea?

like image 456
alec.tu Avatar asked Apr 18 '19 07:04

alec.tu


1 Answers

Just use the ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}.

In all .cu src files, there is no need to manually add

include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}),

because CMake will do it for you.

But for .cpp src files, if you need to include <cuda_runtime.h>, you must manually add

include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) 

in your CMakeLists.txt.

like image 105
Leo Xu Avatar answered Oct 31 '22 19:10

Leo Xu