CMake找不到CUDA:“找不到cmake模块文件:CMakeDetermineCUDACompiler.cmake”

时间:2018-12-19 21:19:51

标签: c++ cmake cuda

我正在尝试编写需要cuda功能的CMake文件。咨询this answer,我将此行添加到了CMakeLists.txt:

set(CMAKE_CUDA_COMPILER  /usr/local/cuda-9.2/bin/nvcc)

但是当使用cmake命令时,它仍然会抱怨:

yuqiong@yuqiong-G7-7588:/media/yuqiong/DATA/alexnet/src/cpp/train$ cmake .
CMake Error: Could not find cmake module file: CMakeDetermineCUDACompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CUDA_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file: /media/yuqiong/DATA/alexnet/src/cpp/train/CMakeFiles/3.5.1/CMakeCUDACompiler.cmake
CMake Error: Could not find cmake module file: CMakeCUDAInformation.cmake
CMake Error: Could not find cmake module file: CMakeTestCUDACompiler.cmake
-- Configuring incomplete, errors occurred!
See also "/media/yuqiong/DATA/alexnet/src/cpp/train/CMakeFiles/CMakeOutput.log".

哪个看起来令人困惑,因为我不知道在哪里还要设置环境变量?知道为什么set命令不能帮助cmake找到nvcc编译器吗?

以防万一,这里是我的CMakeLists.txt

cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_CUDA_COMPILER  /usr/local/cuda-9.2/bin/nvcc)

project(train LANGUAGES CXX CUDA)

set(CMAKE_CXX_STANDARD 14)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )


add_executable(train train.cu)
target_link_libraries( train ${OpenCV_LIBS} )

2 个答案:

答案 0 :(得分:2)

实际上,您需要Linux上的CMake 3.8才能使用project(train LANGUAGES CUDA)。以前,您需要使用以下旧方法:

FindPackage(CUDA)

并手动添加库。

失败是因为您的CMake版本不支持CUDA,请使用旧方法。

答案 1 :(得分:0)

对于任何偶然发现此问题的人,这是我使用的最终CMakeLists.txt文件:

cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_CUDA_COMPILER  /usr/local/cuda-9.2/bin/nvcc)

project(train)
include(FindCUDA)

set(CMAKE_CXX_STANDARD 14)
find_package( OpenCV REQUIRED )
find_package(CUDA REQUIRED)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -gencode arch=compute_30,code=sm_30)

include_directories( ${OpenCV_INCLUDE_DIRS} )

cuda_add_executable(train train.cu)
target_link_libraries( train ${OpenCV_LIBS} )