Cuda Clang and OS X Mavericks

后端 未结 6 1137
遇见更好的自我
遇见更好的自我 2020-11-29 09:37

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

6条回答
  •  离开以前
    2020-11-29 10:22

    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)
    
    

提交回复
热议问题