Antithesis
Antithesis

Reputation: 337

CUDA compilation errors on Mac

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 = nvcc
CUDA_INSTALL_PATH := /Developer/NVIDIA/CUDA-7.5
LIBS := -I. -I$(CUDA_INSTALL_PATH)/include
CUDA_LIBS := -L$(CUDA_INSTALL_PATH)/lib -lcudart

SRCDIR = src
OBJDIR = obj
BINDIR = bin
INClDIR = includes

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 $@ $(LIBS) -c $(OBJECTS)
    @echo "Linking complete!"

$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cu
    @$(GCC) $(LIBS) -c *.cu -o $@
    @echo "Compiled "$<" successfully!"

.PHONEY: clean
clean:
    @$(rm)   $(OBJECTS)
    @echo "Cleanup complete!"
remove: clean
    @$(rm) $(BINDIR)/$(TARGET)
    @echo "Executable removed!"

I get the following error

mkdir -p bin
nvcc -o bin/bfs -I. -I/Developer/NVIDIA/CUDA-7.5/include -c obj/main.o obj/square.o
nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified
make: *** [bin/bfs] Error 1

What am I doing wrong here.

Upvotes: 0

Views: 280

Answers (1)

Robert Crovella
Robert Crovella

Reputation: 151799

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.

Upvotes: 1

Related Questions