CUDA 5 shared amd64 library

I know there are already a ton of topics along this line, but the solution to all of them seemed to be either add “-Xcompiler -fPIC” which I have already done, or recompile some library that they’re linking against, and I’ve tried pulling out all dependencies on any libraries so that my link step has NO external libraries.

So I am using cuda 5, nsight eclipse edition, g++ version 4.1.2 on rhel 5.5, and java 1.6.0_21 64bit if that matters (shouldn’t I imagine).

I want to build a shared library because ultimately I want to call it with jni, but currently I have NO jni stuff in the project config or in the code. With my current config a compile step in the console output looks like:

nvcc --device-c -G -O0 -XCompiler -fPIC -g -gencode arch=compute_20,code=sm_20 -m64 -x cu -o "<output object name>" "<input cu file name>"

and for cpp files:

nvcc -G -g -O0 -m64 -Xcompiler -fPIC --compile -x c++ -o "<output object name>" "<input cpp file name>"

so note that “-Xcompiler -fPIC” is present in both cases. As an extra check I went into the build directory for the project and did a

find . -name "*.o" -exec file '{}' \;

and the output happily reported “ELF 64-bit relocatable, AMD x86-64” for ALL files. To me the key word there is relocatable. Now the trouble happens when I get down to the final link step which in the console looks like:

nvcc --relocatable-device-code=true -gencode arch=compute_20,code=sm_20 -m64 -shared -link -o "<final library name>.so" <space separated list of all the .o files>

/usr/bin/ld: /tmp/tmpxft_<some numbers>-4_<library name>_dlink.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
<same tmp file name as above>: could not read symbols: Bad value

Any help that anyone can provide would be greatly appreciated.

PS: again I’m sorry if this has been answered, but none of the existing answers seemed to be what I needed. Also sorry if there are any typos, my dev machine doesn’t have internet access so I have to type stuff over manually. anything between <> is a placeholder for the described content.