x86-64 linking CUDA object files into a .so Linux

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.

Suggestions? Using openSuSE 10.2

Thanks,
baver

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).

Has anyone figured out any other workarounds for this? Reconfiguring my app at this stage isn’t much of an option for me.

Thanks,
Brian

aha, the easiest thing by far (if you have all the libraries to do so) is to build your project in 32 bit mode for emulation.

Never mind, thought I had it but haven’t tried for device emulation yet.

Did anyone ever manage to find a work-around for this in the end without using -O3? I have the same problem, also running openSuse 10.2.

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.

#include <stdio.h>
extern “C” void test()
{
printf(“test\n”);
}

nvcc -o test.o -shared -c test.cu -Xcompiler -fPIC
gcc -o libtest.so -shared test.o

This works fine and the library can be linked into my main application. However, adding -deviceemu as below gives an error.

nvcc -o test.o -shared -c test.cu -Xcompiler -fPIC -deviceemu
gcc -o libtest.so -shared test.o

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

tbrandvik,

you must be picking up some 1.0 header files.
in 1.1 we deprecated

double __saturate(double)

it should work when you’re picking up the right headers

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.