CUDA compilation errors on Mac

前端 未结 1 608
太阳男子
太阳男子 2021-01-26 07:52

I\'m using the following Makefile to compile a CUDA C program. This follows pretty much the same pattern that I use in most of my C projects.

TARGET = bfs

GCC =         


        
相关标签:
1条回答
  • 2021-01-26 08:36

    This seemed to work for me:

    TARGET = bfs
    
    SRCDIR = src
    OBJDIR = obj
    BINDIR = bin
    INClDIR = includes
    
    CUDA_INSTALL_PATH := /usr/local/cuda
    GCC := $(CUDA_INSTALL_PATH)/bin/nvcc
    LIBS := -I. -I$(SRCDIR) -I$(CUDA_INSTALL_PATH)/include -I$(INClDIR)
    CUDA_LIBS := -L$(CUDA_INSTALL_PATH)/lib64 -lcudart
    
    SOURCES := $(wildcard $(SRCDIR)/*.cu)
    INCLUDES := $(wildcard $(INClDIR)/*.h)
    OBJECTS := $(SOURCES:$(SRCDIR)/%.cu=$(OBJDIR)/%.o)
    rm = rm -f
    
    $(BINDIR)/$(TARGET) : $(OBJECTS)
            mkdir -p $(BINDIR)
            $(GCC) -o $@  $(OBJECTS)
            @echo "Linking complete!"
    
    $(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cu
            @$(GCC) $(LIBS) -c $(SRCDIR)/*.cu -odir $(OBJDIR)
            @echo "Compiled "$<" successfully!"
    
    .PHONEY: clean
    clean:
            @$(rm)   $(OBJECTS)
            @echo "Cleanup complete!"
    remove: clean
            @$(rm) $(BINDIR)/$(TARGET)
            @echo "Executable removed!"
    

    I tested on linux. You will need to change CUDA_INSTALL_PATH back to wherever it is on your machine.

    Note that your use of *.cu on the compile step results in a single invocation of nvcc to compile all the source files. There's nothing wrong with this per se, but it will only generate a single "Compiled ... successfully!" message, as there is only one invocation of nvcc to create all the objects.

    0 讨论(0)
提交回复
热议问题