I'm trying to compile a .so library using nvcc 6.0 from separate .cu files. I managed to compile each file separately using the -rdc=true. When I try to link my libraries using c I get a bunch of errors. I have compiled already from a single library. I read in a question from nvcc 5.0 that this is not supported here. I went into the manual of nvcc 6.0 but could not find (or understand) if that's the case. Bellow is my makefile (I'm not very experienced on writing makefiles so any advice is very welcomed). The error is pasted afterwards
NCC = /usr/local/cuda-6.0/bin/nvcc
CC = g++
LCUDA = -L/usr/local/cuda/lib64 -lcuda -lcudart
LNUM = -lm
OOP = -arch=sm_30 -rdc=true --shared -Xcompiler -fPIC -c
all: cuda_ddm.so
cuda_ddm.so : wfpt.o stationary.o
$(CC) -Wall -shared -include ./c_cuda_ddm.h -o $@ $^ $(LCUDA)
wfpt.o : wfpt.cu
$(NCC) $(OOP) $@ $^
test.o : test.cu
$(NCC) $(OOP) $@ $^
The errors:
(Edit: I changed the compiler error to account for the current situation.)
/usr/local/cuda-6.0/bin/nvcc -arch=sm_30 -rdc=true --shared -Xcompiler -fPIC -c wfpt.o wfpt.cu
/usr/local/cuda-6.0/bin/nvcc -arch=sm_30 -rdc=true --shared -Xcompiler -fPIC -c test.o test.cu
g++ -Wall -shared -o cuda_ddm.so wfpt.o test.o -L/usr/local/cuda/lib64 -lcuda -lcudart
test.o: In function `big_random_block(int)':
tmpxft_00003c24_00000000-3_test.cudafe1.cpp:(.text+0x5e): multiple definition of `big_random_block(int)'
wfpt.o:tmpxft_00003bc7_00000000-3_wfpt.cudafe1.cpp:(.text+0x5e): first defined here
test.o: In function `big_random_block_int(int)':
tmpxft_00003c24_00000000-3_test.cudafe1.cpp:(.text+0xde): multiple definition of `big_random_block_int(int)'
wfpt.o:tmpxft_00003bc7_00000000-3_wfpt.cudafe1.cpp:(.text+0xde): first defined here
test.o: In function `value(float, float, int)':
tmpxft_00003c24_00000000-3_test.cudafe1.cpp:(.text+0x169): multiple definition of `value(float, float, int)'
wfpt.o:tmpxft_00003bc7_00000000-3_wfpt.cudafe1.cpp:(.text+0x169): first defined here
test.o: In function `__device_stub__Z14float_to_colorPhPKf(unsigned char*, float const*)':
tmpxft_00003c24_00000000-3_test.cudafe1.cpp:(.text+0x788): multiple definition of `__device_stub__Z14float_to_colorPhPKf(unsigned char*, float const*)'
wfpt.o:tmpxft_00003bc7_00000000-3_wfpt.cudafe1.cpp:(.text+0xb30): first defined here
test.o: In function `float_to_color(unsigned char*, float const*)':
tmpxft_00003c24_00000000-3_test.cudafe1.cpp:(.text+0x7f9): multiple definition of `float_to_color(unsigned char*, float const*)'
wfpt.o:tmpxft_00003bc7_00000000-3_wfpt.cudafe1.cpp:(.text+0xba1): first defined here
test.o: In function `__device_stub__Z14float_to_colorP6uchar4PKf(uchar4*, float const*)':
tmpxft_00003c24_00000000-3_test.cudafe1.cpp:(.text+0x81e): multiple definition of `__device_stub__Z14float_to_colorP6uchar4PKf(uchar4*, float const*)'
wfpt.o:tmpxft_00003bc7_00000000-3_wfpt.cudafe1.cpp:(.text+0xbc6): first defined here
test.o: In function `float_to_color(uchar4*, float const*)':
tmpxft_00003c24_00000000-3_test.cudafe1.cpp:(.text+0x88f): multiple definition of `float_to_color(uchar4*, float const*)'
wfpt.o:tmpxft_00003bc7_00000000-3_wfpt.cudafe1.cpp:(.text+0xc37): first defined here
collect2: error: ld returned 1 exit status
make: *** [cuda_ddm.so] Error 1
Edit:
To clarify the situation, I changed the code to be 100% sure that there is no overlapping code in both files. I have in both a # include "c_cuda_ddm.hcu"
with the following content:
# ifndef DDM_HEADER
# define DDM_HEADER
#include "book.h"
#include "math.h"
# define TOL 1e-7
# define PI 3.1415926535
# define DIM_X 0
# define DIM_Y 2
# define DIM_U 2
# define DIM_THETA 3
# define DIM_PTHETA 0
# define INDEX_V 0
# define INDEX_A 1
# define INDEX_W 2
# define CUE_LEFT 1
# define CUE_RIGHT 0
# define ANTISACCADE_TYPE 0
# define PROSACCADE_TYPE 1
// Number of threads for the predictive posterior
# define DDMBLOCKS 256
# define PPBLOCKS 1024
# define LLHBLOCKS 16
# endif
__device__ double lp_ddm(double t, double v, double a, double w);
extern "C"
int llh_ddm(double *t, double *v, double *a, double *w, int ny,
double *llh);
extern "C"
int llh_stationary_antisaccades(double *x, double *y, double *u,
double *theta, double *ptheta, int ny, double *llh);
extern "C"
int lpp_stationary_antisaccades(double *x, double *y, double *u,
double *theta, double *ptheta, int ny, int ns, double *llh);