Hey team,
I’m trying to compile a code using separate compilation and link it all together with clang++.
Everything compiles fine but I’m getting an error in the linking step
Undefined symbols for architecture x86_64:
"d_moveParticles(double3*, double3*, double, int)", referenced from:
moveParticles(cudaGraphicsResource**, double3*, double, int) in moveAtoms.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [bin/CUDADSMC] Error 1
d_moveParticles is a global function that is called by the host function moveParticles.
Here is my makefile
NVCCFLAGS = -m 64 -arch=sm_35
BUILDDIR = bin/
OBJDIR = $(BUILDDIR)obj/
SRCDIR = src/
EXEC = $(BUILDDIR)CUDADSMC
INCLUDE += -I include/
all: $(EXEC)
$(EXEC): $(addprefix $(OBJDIR), main.o gpuCode.o magneticField.o moveAtoms.o setUp.o openGLhelpers.o shader.o)
@echo 'Building file: $<'
@echo 'Invoking: NVCC Linker'
clang++ -o $@ $(INCLUDE) $^ $(LIB) $(CUDA_LIB) -lc++ -v -lcudart -lglfw3 -lGLEW -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo
@echo "Finished building: $< $(OK_STRING)"
@echo ' '
$(OBJDIR)gpuCode.o: $(addprefix $(OBJDIR), setUp.o moveAtoms.o magneticField.o)
@echo 'Linking device object files: $<'
@echo 'Invoking: NVCC Linker'
$(NVCC) $(NVCCFLAGS) -dlink -o $@ $^
@echo "Finished linking: $< $(OK_STRING)"
@echo ' '
$(OBJDIR)%.o: $(SRCDIR)%.cpp
@echo 'Building file: $<'
@echo 'Invoking: clang Compiler'
clang++ $(INCLUDE) $(CUDA_INC) -o $@ -c $?
@echo "Finished building: $< $(OK_STRING)"
@echo ' '
$(OBJDIR)%.o: $(SRCDIR)%.cu
@echo 'Building file: $<'
@echo 'Invoking: NVCC Compiler'
$(NVCC) $(NVCCFLAGS) -x cu $(INCLUDE) -o $@ -dc $? -D CUDA7
@echo "Finished building: $< $(OK_STRING)"
@echo ' '
If it makes a difference both d_moveParticles and moveParticles are in the moveAtoms.cu file.
I’m hoping there is a code whizz out there who can help me out. Let me know if anything else is unclear.
Thanks heaps
Chris