【问题标题】:CUDA 5.0, CMake and Make failing on OSX 10.8.3CUDA 5.0、CMake 和 Make 在 OSX 10.8.3 上失败
【发布时间】:2013-04-23 14:06:47
【问题描述】:

我尝试在我的 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

我用谷歌搜索了显示的错误,但找不到任何足够的答案。 尽管cmake 成功了,但任何关于make 失败的想法。

感谢您的帮助。

【问题讨论】:

    标签: macos cuda makefile cmake osx-mountain-lion


    【解决方案1】:

    XCode 中的默认 C 编译器在 OS X Lion 中更改为 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 的路径。

    【讨论】:

    • 您的代码对我不起作用。但从技术上讲,将CUDA_HOST_COMPILER 设置为/usr/bin/gcc 是正确的答案。用我展示的CMakeList.txt 调用cmake . -DCUDA_HOST_COMPILER:FILEPATH=/usr/bin/gcc 有效。谢谢!
    【解决方案2】:

    如果您不想更改您的 CMakeLists.txt,如果您将环境变量 CXX 设置为“gcc”,它就可以工作(假设您的路径中没有任何其他 GCC 在 /usr/bin 之前的路径)。

    CMake 会自动拾取它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-16
      • 2021-03-16
      相关资源
      最近更新 更多