c++ - 如何让cmake找到CUDA

我正在尝试构建 this project ,它具有 CUDA 作为依赖项。但是cmake脚本在系统上找不到CUDA安装:

cls ~/workspace/gpucluster/cluster/build $ cmake ..
-- The C compiler identification is GNU 4.7.1
-- The CXX compiler identification is GNU 4.7.1
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at /usr/share/cmake/Modules/FindCUDA.cmake:488 (message):
  Specify CUDA_TOOLKIT_ROOT_DIR
Call Stack (most recent call first):
  CMakeLists.txt:20 (find_package)

-- 配置不完整,出现错误!

我尝试将其作为环境变量添加到 .bashrc,但没有效果:

export CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-5.5

如何正确指定CUDA_TOOLKIT_ROOT_DIR

最佳答案

cmake 提到 CUDA_TOOLKIT_ROOT_DIR 作为 cmake 变量,而不是环境一。这就是为什么将它放入.bashrc 时它不起作用的原因。如果您查看 FindCUDA.cmake,它会清楚地表明:

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:

cmake -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-5.5 ..

https://stackoverflow.com/questions/19980412/

相关文章:

java - 使Maven构建更快的方法?

visual-studio-2010 - 禁止在构建时创建 *.vshost.exe 和其他文件

c - 如何在 Windows 中使用 MSVC 从命令行构建 DLL

iphone - XCTest.framework 构建错误

eclipse - Java Eclipse 在保存时关闭自动构建工作区

build - WiX x64 平台目标

ant - 如何在使用 ANT 删除目录之前检查目录是否存在?

android - Buck vs Gradle,Android 构建系统的优缺点

c++ - 如何在 Mac OS X (C++) 中使用 dylib

gcc - 如何在编译期间强制 cmake 包含 "-pthread"选项?