CUDA编译器无法编译简单的测试程序

时间:2020-10-21 18:33:58

标签: c++ cmake cuda

我在CUDA中创建了一个模板Clion项目,它似乎根本不起作用。

Clion new projct creation

我唯一更改的是CMakeLists.txt中的这一行:

set(CMAKE_CUDA_COMPILER "/usr/local/cuda-10.1/bin/nvcc")

所以看起来像这样:

cmake_minimum_required(VERSION 3.17)

set(CMAKE_CUDA_COMPILER "/usr/local/cuda-10.1/bin/nvcc")
project(test CUDA)

set(CMAKE_CUDA_STANDARD 14)

add_executable(test main.cu)

set_target_properties(
        test
        PROPERTIES
        CUDA_SEPARABLE_COMPILATION ON)

我尝试从Clion或终端构建程序都没关系,我总是得到:

CMake Error at /snap/clion/129/bin/cmake/linux/share/cmake-3.17/Modules/CMakeTestCUDACompiler.cmake:46 (message):
  The CUDA compiler

    "/usr/local/cuda-10.1/bin/nvcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/user/CLionProjects/test/cmake-build-debug/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/make cmTC_bafff/fast && /usr/bin/make  -f CMakeFiles/cmTC_bafff.dir/build.make CMakeFiles/cmTC_bafff.dir/build
    make[1]: Entering directory '/home/user/CLionProjects/test/cmake-build-debug/CMakeFiles/CMakeTmp'
    Building CUDA object CMakeFiles/cmTC_bafff.dir/main.cu.o
    /usr/local/cuda-10.1/bin/nvcc     -x cu -c /home/user/CLionProjects/test/cmake-build-debug/CMakeFiles/CMakeTmp/main.cu -o CMakeFiles/cmTC_bafff.dir/main.cu.o
    In file included from /usr/local/cuda-10.1/bin/../targets/x86_64-linux/include/cuda_runtime.h:83,
                     from <command-line>:
    /usr/local/cuda-10.1/bin/../targets/x86_64-linux/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
      138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
          |  ^~~~~
    make[1]: *** [CMakeFiles/cmTC_bafff.dir/build.make:86: CMakeFiles/cmTC_bafff.dir/main.cu.o] Error 1
    make[1]: Leaving directory '/home/user/CLionProjects/test/cmake-build-debug/CMakeFiles/CMakeTmp'
    make: *** [Makefile:141: cmTC_bafff/fast] Error 2
        

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:4 (project)


-- Configuring incomplete, errors occurred!
See also "/home/user/CLionProjects/test/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/home/user/CLionProjects/test/cmake-build-debug/CMakeFiles/CMakeError.log".

我使用Ubuntu 20,Clion(2020.2.4)来自最新的快照。我还尝试使用gcc和g ++(7、8和9)和CMake(3.17(snap),3.18和3.19)的不同版本运行它。 另外:

  • Nvidia驱动程序版本:455.23.0
  • CUDA版本:11.1

路径/usr/local/cuda-10.1/bin/nvcc是正确的。

1 个答案:

答案 0 :(得分:1)

当我将默认系统gcc的版本从9更改为8时,它开始工作。(Ubuntu 20的默认gcc版本是9)

sudo update-alternatives --config gcc
相关问题