Cuda Clang and OS X Mavericks

11,036

Solution 1

The issue with 10.9 is that gcc is actually clang. Please try latest CUDA toolkit and explicitely point NVCC to use /usr/bin/clang (nvcc -ccbin /usr/bin/clang). This way NVCC will know it's dealing with clang.

Solution 2

This is an extension of the answer provided by Eugene:

The CUDA toolkit download for Mac OSX 10.9 has been posted to the CUDA download page

It supports XCode 5 on 10.9, and will automatically use clang instead of gcc, FYI.

IF you are using XCode 5 on 10.8, please see the release notes:

· On Mac OS X 10.8, if you install XCode 5, including the command-line tools, the gcc compiler will get replaced with clang. You can continue to successfully compile with nvcc from the command-line by using the --ccbin /usr/bin/clang option, which instructs nvcc to use the clang compiler instead of gcc to compile any host code passed to it. However, this solution will not work when building with NSight Eclipse Edition. An alternative solution that will work from the command-line and with NSight Eclipse Edition is to download an older version of the command-line tools package from the Apple Developer website after installing XCode 5, which will re-install gcc to /usr/bin. In order to do this, go to

http://developer.apple.com/downloads/index.action

sign in with your Apple ID, and search for command-line tools using the search pane on the left side of the screen.

Solution 3

The problem actually was there before OS X Mavericks, I had the same problem with Moutain Lion and the answer from Eugene is 100% correct.

However, it seems that my Geforce card is not recognized as a CUDA capable device since the upgrade to Mavericks and it seems that people using softwares that use CUDA are having the same problems.

So better not update right now

Solution 4

Clang become the default compiler with OsX Maverick release, gcc and g++ commands are redirected to the clang compiler. You can download gcc compiler via homebrew and link gcc and g++ commands back to the gcc compiler via following the steps below.

$ brew install gcc48
[...]

$ sudo mkdir /usr/bin/backup && sudo mv /usr/bin/gcc /usr/bin/g++ /usr/bin/backup
$ sudo ln -s /usr/local/bin/gcc-4.8 /usr/bin/gcc
$ sudo ln -s /usr/local/bin/g++-4.8 /usr/bin/g++

I have found the solution on this article: http://gvsmirnov.ru/blog/tech/2014/02/07/building-openjdk-8-on-osx-maverick.html#all-you-had-to-do-was-follow-the-damn-train-cj

Solution 5

I have just downloaded CUDA 5.5, installed under Mac OSX 10.8.5, with Xcode 5.0.2, and updated command line tools in Xcode. But I couldn't get the CUDA sample "nbody" to compile. I got all kinds of funny error messages, like

 clang error: unsupported option '-dumpspecs'
I thought I had solved that one by the help of some other web pages, but then other problems kept creeping up (e.g., GLEW not found, CUDA samples path undefined, ...). (And the provided makefiles and cmake files seemed just too contrived, so that I couldn't find the bug.)

So I rolled my own makefile. I'm posting it here, in the hope that it might help others save some hours.

    #!/usr/bin/make -R

    # Simple Makefile for a CUDA sample program
    # (because the provided ones don't work! :-( )
    #
    # We assume that all files in this directory produce one executable.
    # Set your GPU version in variable NVCC below
    #
    # Developed and tested under Mac OS X 10.8.5;
    # under Linux, you probably need to adjust a few paths, compiler options, and #ifdef's.
    #
    # Prerequisites:
    # - CUDA 5.5
    # - The "Command Line Tools" installed via XCode 5
    # - DYLD_FALLBACK_LIBRARY_PATH or DYLD_LIBRARY_PATH must include
    #      /Developer/NVIDIA/CUDA-5.5/lib:/Developer/NVIDIA/CUDA-5.5/samples/common/lib/darwin
    #
    # GZ Dec 2013


    # -------- variables and settings ---------
    #

    CUDA := /Developer/NVIDIA/CUDA-5.5

    NVCC := nvcc -ccbin /usr/bin/clang -arch=sm_30 --compiler-options -Wall,-ansi,-Wno-extra-tokens
    #  -ccbin /usr/bin/clang  is needed with XCode 5 under OSX 10.8
    #  -arch=sm_30  is needed for my laptop (it does not provide sm_35)

    INCFLAGS := -I $(CUDA)/samples/common/inc

    TARGET := nbody

    OBJDIR := obj

    MAKEFLAGS := kR

    .SUFFIXES: .cu .cpp .h

    ALLSOURCES := $(wildcard *.cu *.cpp)
    ALLFILES := $(basename $(ALLSOURCES))
    ALLOBJS := $(addsuffix .o,$(addprefix $(OBJDIR)/,$(ALLFILES)))

    DEPDIR := depend

    # --------- automatic targets --------------

    .PHONY: all
    all: $(OBJDIR) $(DEPDIR) $(TARGET) 
        @true

    $(OBJDIR):
        mkdir $@


    # --------- generic rules --------------

    UNAME = $(shell uname)
    ifeq ($(UNAME), Darwin)  # Mac OS X
    # OpenGL and GLUT are frameworks
    LDFLAGS = -Xlinker -framework,OpenGL,-framework,GLUT,-L,$(CUDA)/samples/common/lib/darwin,-lGLEW
    endif

    $(TARGET): $(ALLOBJS)
        $(NVCC) $^ $(LDFLAGS) -o $@

    $(OBJDIR)/%.o: %.cu
        $(NVCC) -c $(INCFLAGS) $ $@

    $(DEPDIR)/%.d : %.cpp $(DEPDIR)
        @echo creating dependencies for $ $@

    $(DEPDIR):
        mkdir $@


    # ------ administrative stuff -------

    .PHONY: clean

    clean:
        rm -f *.o $(TARGET)
        rm -rf $(DEPDIR) $(OBJDIR)


    echo:
        @echo $(ALLSOURCES)
        @echo $(ALLFILES)
        @echo $(ALLOBJS)

Share:
11,036
Arthur Pajot
Author by

Arthur Pajot

Updated on July 29, 2022

Comments

  • Arthur Pajot
    Arthur Pajot almost 2 years

    I'm currently trying to build a Cuda project with Cmake on MacOS 10.9. My C and C++ compiler are gcc, but it seems that since Mavericks gcc and g++ links to clang, which is not supported by CUDA.

    Has anyone found a good solution to use the real gcc, or to make clang work without "dumpspecs"?

  • kamjagin
    kamjagin over 10 years
    This does it, but it seems that a new problem arises on 10.9 and Xcode 5: The default stdlib is now libc++, which seems to produce new errors with nvcc. So you also need to add the -stdlib=libstdc++ flag (via -Xcompiler if specified to nvcc directly)