【问题标题】:Can't find CUDA_INCLUDE_DIRS in latest CMAKE [duplicate]在最新的 CMAKE 中找不到 CUDA_INCLUDE_DIRS [重复]
【发布时间】:2019-04-18 07:41:18
【问题描述】:

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

有什么想法吗?

【问题讨论】:

  • 如果您没有使用旧版 CUDA 构建宏,您为什么希望设置像 CUDA_INCLUDE_DIRS 这样的旧版构建变量?
  • 那么如何在较新版本的cmake中找到cuda包含目录?
  • 这与您最初提出的问题不同——但可能类似于stackoverflow.com/a/6904431/681865
  • 它看起来像原来的问题,但它不能像后来这样的问题那么受欢迎:stackoverflow.com/questions/51756562/…

标签: cmake cuda


【解决方案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 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    • 2020-11-10
    • 2017-12-25
    • 2019-12-13
    • 2014-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多