CUDA 5.0,在OSX 10.8.3上使用CMake和Make失败。

4

我尝试在我的Mac OSX 10.8.3上使用CMake编译一个简单的CUDA“Hello World”程序。

调用cmake .似乎成功了。这是我的CMakeList.txt文件:

project(HelloWorld)
cmake_minimum_required(VERSION 2.8)

FIND_PACKAGE(CUDA)

CUDA_INCLUDE_DIRECTORIES(/Developer/NVIDIA/CUDA-5.0/samples/common/inc)
CUDA_ADD_EXECUTABLE(helloWorld helloWorld.cu)

...和输出:

-- The C compiler identification is Clang 4.2.0
-- The CXX compiler identification is Clang 4.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- 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
-- Found CUDA: /Developer/NVIDIA/CUDA-5.0 (found version "5.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mennny/Documents/UNI/6_Semester/0_PMPP/1_exercises/cuda-hello-world

但是随后调用make时会出现以下错误:

[100%] Building NVCC (Device) object CMakeFiles/helloWorld.dir//./helloWorld_generated_helloWorld.cu.o
clang: error: unsupported option '-dumpspecs'
clang: error: no input files
CMake Error at helloWorld_generated_helloWorld.cu.o.cmake:206 (message): Error generating /Users/mennny/Documents/UNI/6_Semester/0_PMPP/1_exercises/cuda-hello-world/CMakeFiles/helloWorld.dir//./helloWorld_generated_helloWorld.cu.o


make[2]: *** [CMakeFiles/helloWorld.dir/./helloWorld_generated_helloWorld.cu.o] Error 1
make[1]: *** [CMakeFiles/helloWorld.dir/all] Error 2
make: *** [all] Error 2
我在谷歌上搜索了出现的错误,但没有找到足够的答案。不知道为什么make失败了,尽管cmake成功了。感谢您的帮助。
2个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
1

在OS X Lion中,XCode的默认C编译器更改为CLang。由于CLang与nvcc不兼容,因此您需要更改nvcc用于非CUDA(主机)代码的编译器。将以下内容添加到您的CMakeList.txt中即可:

if (NOT DEFINED CUDA_HOST_COMPILER AND CMAKE_C_COMPILER_ID STREQUAL "Clang" AND EXISTS /usr/bin/gcc)
  set(CUDA_HOST_COMPILER /usr/bin/gcc CACHE FILEPATH "Host side compiler used by NVCC")
  message(STATUS "Setting CMAKE_HOST_COMPILER to /usr/bin/gcc instead of ${CMAKE_C_COMPILER}.")
endif()

如果需要,请调整gcc的路径。


1
你的代码对我不起作用。但从技术上讲,将CUDA_HOST_COMPILER设置为/usr/bin/gcc是正确的答案。使用我展示的CMakeList.txt调用cmake . -DCUDA_HOST_COMPILER:FILEPATH=/usr/bin/gcc可以解决问题。谢谢! - Mennny

0
如果您不想更改CMakeLists.txt文件,可以将环境变量CXX设置为"gcc"(假设在/usr/bin之前的路径中没有其他GCC),这样就可以正常工作了。 CMake会自动检测到它。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,