I have 3 CUDA files which I am trying to complile inside ./Obj/FILENAME.o and create ./run executable. I try it with this script:
IDIR = ./
ODIR = ./Obj/
SDIR = ./
CFLAGS = -I $(IDIR)
NVCC = nvcc
NVCCFLAGS = $(CFLAGS) --ptxas-options=-v
_OBJ = File.o kmeans.o wtime.o
OBJ = $(patsubst %, $(ODIR)%, $(_OBJ))
$(ODIR)%.o: $(SDIR)%.cu
$(NVCC) -c -o $@ $< $(NVCCFLAGS)
run: $(OBJ)
$(NVCC) -o $@ $^ $(NVCCFLAGS)
.PHONY: clean
clean:
rm -f $(ODIR)*.o *~ core $(INCDIR)/*~ run $(SDIR)*~
But I get title error, one screenshot of the complete output:
The header file where I declare it is:
#ifndef _H_KMEANS
#define _H_KMEANS
#include <stdio.h>
#include <stdlib.h>
#include <string.h> /* strtok() */
#include <sys/types.h> /* open() */
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h> /* getopt() */
#include <assert.h>
#include "File.h"
#include "wtime.h"
#define msg(format, ...) do { fprintf(stderr, format, ##__VA_ARGS__); } while (0)
#define err(format, ...) do { fprintf(stderr, format, ##__VA_ARGS__); exit(1); } while (0)
#define malloc2D(name, xDim, yDim, type) do { \
name = (type **)malloc(xDim * sizeof(type *)); \
assert(name != NULL); \
name[0] = (type *)malloc(xDim * yDim * sizeof(type)); \
assert(name[0] != NULL); \
for (size_t i = 1; i < xDim; i++) \
name[i] = name[i-1] + yDim; \
} while (0)
#ifdef __CUDACC__
inline void checkCuda(cudaError_t e) {
if (e != cudaSuccess) {
// cudaGetErrorString() isn't always very helpful. Look up the error
// number in the cudaError enum in driver_types.h in the CUDA includes
// directory for a better explanation.
err("CUDA Error %d: %s\n", e, cudaGetErrorString(e));
}
}
inline void checkLastCudaError() {
checkCuda(cudaGetLastError());
}
#endif
float** kmeans(float**, int, int, int, float, int*, int*);
int _debug;
extern int _debug;
#endif
And this header is included in kmeans.cu and File.cu sources.
Anyone know why I get that error? Thank you.
转载于:https://stackoverflow.com/questions/53249128/multiple-definitions-of-debug-compiler-error