Error make a shared library in x86_64

When I try and compile a project to a shared library, I get this error:

/usr/bin/ld: obj/release/cuRTIV.cu_o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC

obj/release/cuRTIV.cu_o: could not read symbols: Bad value

collect2: ld returned 1 exit status

I am using the makefile that comes with the SDK with a few changes

# Add source files here

EXECUTABLE      := libcuRTIV.so

# CUDA source files (compiled with cudacc)

CUFILES         := cuRTIV.cu

# CUDA dependency files

CU_DEPS         := cuRTIV_kernel.cu

# C/C++ source files (compiled with gcc / c++)

CCFILES         := cuRTIV_cpp.cpp

################################################################################

# Rules and targets

include ../../common/common.mk

CXXFLAGS += -fPIC

CFLAGS += -fPIC

LINK += -shared

cuRTIV.cu is getting compiled with nvcc, so I can’t pass -fPIC to it. Any ideas?

No, the fix that I had in here earlier doesn’t solve the problem. Still stuck.

I believe you need to use “-Xcompiler -fPIC”.

Thanks Patrick. That let it compile. Now I’ll see if it works.

NVCCFLAGS += -Xcompiler -fPIC

Ive been trying to create a shared object file, ran into the same problem you did, but

didn’t solve the problem, what should the final makefile used to create a shared object look like? Whenever i add the LINK += -shared, i get the error:

obj/release/mySo.cu_o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC obj/release/mySo.cu_o: could not read symbols: Bad value

Try recompile the commons stuff with fPIC flags. Worked for me…