我正在使用以下Makefile来编译CUDA C程序。这跟我在大多数C项目中使用的模式大致相同。
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!"
我收到以下错误
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
我在这里做错了什么。
答案 0 :(得分:1)
这似乎对我有用:
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!"
我在linux上测试过。您需要将CUDA_INSTALL_PATH
更改回计算机上的任何位置。
请注意,在编译步骤中使用*.cu
会导致单nvcc
次调用以编译所有源文件。这本身并没有什么不妥,但它只会产生一个单独的编译......成功!&#34;消息,因为只有一个nvcc
的调用来创建所有对象。