cmake + shared library + libcutil => stabby

I’ve been trying to get a cuda code to compile as a shared library for quite some time now. I got sick of mucking with make files so I tried the cmake script. I can get the code to compile and build as an executable, however, if i try and build it as a shared library, i get this error in the linker:

[ 66%] Building CXX object src/CMakeFiles/h_test_lib.dir/cuda/hadamard.cu_h_test_lib_generated.o

Linking CXX shared library

/usr/bin/ld: /usr/local/cuda/NVIDIA_CUDA_SDK/lib/libcutil.a(cutil.cpp_o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC

/usr/local/cuda/NVIDIA_CUDA_SDK/lib/libcutil.a: could not read symbols: Bad value

collect2: ld returned 1 exit status

make[2]: *** [src/] Error 1

make[1]: *** [src/CMakeFiles/h_test_lib.dir/all] Error 2

make: *** [all] Error 2

After tooling around with compiler flags and such for a few hours, i give in. Any ideas?

I’m using Ubuntu 8.04 with the latest driver and cuda 2.0 toolkit and sdk.



Are you linking the static library libcutil.a to the shared library you are trying to create? You can’t do that. You’ll need to decouple your lib from cutil or build a shared version of cutil to link it to.

Rebuild your common files (“make” in SDK/common) after editing your file as in this post:…st&p=363047