我正在尝试编写需要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} )
最佳答案
实际上,您需要Linux上的CMake 3.8才能使用project(train LANGUAGES CUDA)
。以前,您需要使用以下旧方法:
FindPackage(CUDA)
并手动添加库。
失败是因为在您的CMake版本中没有对CUDA的本机支持,请使用旧方法。
关于c++ - CMake找不到CUDA:“找不到cmake模块文件:CMakeDetermineCUDACompiler.cmake”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53859271/