【问题标题】:Missing variable is: CMAKE_CUDA_COMPILE_WHOLE_COMPILATION缺少的变量是:CMAKE_CUDA_COMPILE_WHOLE_COMPILATION
【发布时间】:2020-08-01 18:32:04
【问题描述】:

我正在尝试使用 CMake 使用 cuda 编译库。

我希望 cuda 是可选的,即如果系统上没有 nvcc,我希望我的库能够编译。

这是我检查 CMake 中是否提供 cuda 的方法:

include(CheckLanguage)
check_language(CUDA)
if (CMAKE_CUDA_COMPILER)
    enable_language(CUDA)
else()
    message(WARNING "CUDA not found: GPU features won't be available.")
endif ()

这里是我设置的环境变量:

$> env | grep CXX
CUDAHOSTCXX=/usr/bin/g++-6
CUDACXX=/usr/bin/nvcc
CXX=/usr/bin/g++

这是 cmake 命令的输出:

$> cmake ..
-- The CXX compiler identification is GNU 7.4.0
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for a CUDA compiler
-- Looking for a CUDA compiler - /usr/bin/nvcc
-- The CUDA compiler identification is NVIDIA 9.1.85
-- Check for working CUDA compiler: /usr/bin/nvcc
-- Check for working CUDA compiler: /usr/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Configuring done
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_CUDA_COMPILE_WHOLE_COMPILATION
-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

我没有找到任何有用的关于 CMAKE_CUDA_COMPILE_WHOLE_COMPILATION 的东西。

我怎样才能使这个 cmake 工作?我错过了什么?

【问题讨论】:

    标签: cmake cuda


    【解决方案1】:

    我只是找出问题所在......

    我在调用一个函数

    function(enable_cuda_if_available)
        # Here CUDA is properly found and variable are correctly set
        include(CheckLanguage)
        check_language(CUDA)
        if (CMAKE_CUDA_COMPILER)
            enable_language(CUDA)
        else ()
            message(WARNING "CUDA not found: GPU features won't be available.")
        endif ()
    endfunction()
    
    enable_cuda_if_available()
    # Here CUDA's variables have not been forwarded to the parent scope and leading to an error
    

    我还是不知道如何将 enable_cuda_if_available 设置的所有变量自动转发到父作用域

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 2015-07-25
      • 1970-01-01
      • 2012-09-11
      • 2018-12-21
      • 2012-06-24
      相关资源
      最近更新 更多