2013-04-29 124 views
4

我嘗試在我的Mac OSX 10.8.3上使用CMake編譯一個簡單的CUDA「Hello World」。CUDA 5.0,CMake和Make在OSX上失敗10.8.3

調用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後失敗,出現以下錯誤(S):

[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 

我GOOGLE所示錯誤,但找不到任何足夠的答案。 任何想法爲什麼make失敗,但cmake成功。

感謝您的幫助。

回答

1

X 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。

+1

您的代碼不適用於我。但是從技術上說''CUDA_HOST_COMPILER'設置爲'/ usr/bin/gcc'是正確的答案。調用'cmake。 -DCUDA_HOST_COMPILER:FILEPATH =/usr/bin/gcc'與我顯示的'CMakeList.txt'起作用。謝謝! – Mennny 2013-04-30 08:41:48

0

如果你不想改變你的CMakeLists.txt,它可以工作,如果你設置環境變量CXX爲「gcc」(假設你的路徑中沒有任何其他GCC在/ usr /倉)。

CMake會自動提取它。