I have a couple global functions I want to link into a shared library object on x86-64 linux with device emulation, but when linking I get the following error:
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/…/…/…/…/x86_64-suse-linux/bin/ld: least_squares_gpu.o: relocation R_X86_64_PC32 against `__saturate’ can not be used when making a shared object; recompile with -fPIC
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/…/…/…/…/x86_64-suse-linux/bin/ld: final link failed: Bad value
CFLAGS used to compile the .CU file least_squares_gpu.cu:
-Xcompiler -fPIC -DPIC -g -Xcompiler -std=gnu99 -Xopencc -fPIC -DPIC -I…/include -I./ -I…/include -I/usr/include -DCUDACC -DDEBUG -I/home/baver/NVIDIA_CUDA_SDK/common/inc -deviceemu
Compilation works fine without -deviceemu flag. All other non-CUDA files which are also being linked have -fPIC as part of the CFLAGS.
I found a hack/workaround to this problem, if I’m using -O3 setting in gcc to compile .o file , the functions which make this problem appear like __saturate get inlined and linking is done.
Tis sort of not the best thing for debugging. I ended up with having my cuda code built into both .so and executable(for debugging).
Also, does anyone know if this problem has been fixed in 1.1? If so, I’ll probably just switch to Red Hat.
Edit:
Just thought I should include a quick example. I think I’m using nvcc/gcc in the right way, but I might be wrong. If anyone could try this out in 1.1 I would be very grateful.
ld: test.o: relocation R_X86_64_PC32 against `__saturate’ can not be used when making a shared object; recompile with -fPIC
ld: final link failed: Bad value
Sorry, probably should have been clearer. I am actually using 1.0, but was wondering if it works in 1.1. From what you’re saying though, it sounds like it should do so I’ll have a go at upgrading. Thanks for your help.