How to let cmake find CUDA(如何让cmake找到CUDA)
问题描述
我正在尝试构建 这个项目,它具有 CUDA 作为依赖项.但是cmake脚本在系统上找不到CUDA安装:
I am trying to build this project, which has CUDA as a dependency. But the cmake script cannot find the CUDA installation on the system:
-- 配置不完整,出现错误!
-- Configuring incomplete, errors occurred!
我尝试将其作为环境变量添加到 .bashrc
,但没有效果:
I've tried adding it as an environment variable to .bashrc
, to no effect:
如何正确指定CUDA_TOOLKIT_ROOT_DIR
?
推荐答案
cmake 提到 CUDA_TOOLKIT_ROOT_DIR
作为 cmake 变量,而不是环境一.这就是为什么将它放入.bashrc 时它不起作用的原因.如果您查看 FindCUDA.cmake,它会清楚地表明:
cmake mentioned CUDA_TOOLKIT_ROOT_DIR
as cmake variable, not environment one. That's why it does not work when you put it into .bashrc. If you look into FindCUDA.cmake it clearly says that:
脚本将提示用户指定 CUDA_TOOLKIT_ROOT_DIR 如果前缀不能由系统路径中 nvcc 的位置确定,需要被指定为 find_package().要使用不同的安装版本工具包在运行 cmake 之前设置环境变量 CUDA_BIN_PATH(例如 CUDA_BIN_PATH=/usr/local/cuda1.0 而不是默认的/usr/local/cuda)或者在配置后设置 CUDA_TOOLKIT_ROOT_DIR.如果你改变值CUDA_TOOLKIT_ROOT_DIR,依赖路径的各种组件将搬家了.
The script will prompt the user to specify CUDA_TOOLKIT_ROOT_DIR if the prefix cannot be determined by the location of nvcc in the system path and REQUIRED is specified to find_package(). To use a different installed version of the toolkit set the environment variable CUDA_BIN_PATH before running cmake (e.g. CUDA_BIN_PATH=/usr/local/cuda1.0 instead of the default /usr/local/cuda) or set CUDA_TOOLKIT_ROOT_DIR after configuring. If you change the value of CUDA_TOOLKIT_ROOT_DIR, various components that depend on the path will be relocated.
所以把CUDA_BIN_PATH
放到.bashrc或者指定CUDA_TOOLKIT_ROOT_DIR
到cmake:
So put CUDA_BIN_PATH
into .bashrc or specify CUDA_TOOLKIT_ROOT_DIR
to cmake:
这篇关于如何让cmake找到CUDA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!