Issue: Undefined reference to fatbinwrap

Hi,
I created a shared library containing cuda (and Thrust) code libgpu-mine.so.

when I link this library libgpu-mine.so from other cuda code I get this linker error:

[100%] Building NVCC intermediate link file CMakeFiles/test.dir/./test_intermediate_link.o
Linking CXX executable test


`__fatbinwrap_66_tmpxft_0000235d_00000000_12_cuda_device_runtime_compute_50_cpp1_ii_5f6993ef'
collect2: error: ld returned 1 exit status

The command issued by Cmake when compiling a main.cu source file calling functions in libgpu-mine.so is the following:

/usr/bin/g++-4.8     -O2 -g -DNDEBUG    CMakeFiles/test.dir/./test_generated_main.cu.o CMakeFiles/test.dir/./test_intermediate_link.o  -o test -rdynamic /usr/local/cuda/lib64/libcudart.so /<path_to_code>/local/lib/libgpu-mine.so /usr/local/cuda/lib64/libcudart.so -lcuda /<path_to_code>/local/lib/libgpu-mine.so -lcuda -Wl,-rpath,/usr/local/cuda/lib64:/<path_to_code>/local/lib 
/<path_to_code>/local/lib/libgpu-mine.so: undefined reference to `__fatbinwrap_66_tmpxft_0000235d_00000000_12_cuda_device_runtime_compute_50_cpp1_ii_5f6993ef'
collect2: error: ld returned 1 exit status

I am using CUDA 6.5 with a K40, gcc 4.8 on Ubuntu 14.04.
libgpu-mine is created using cmake with SEPARABLE_COMPILATION_ON and the following compilation flags:

-keep -DDEBUG -gencode arch=compute_35,code=sm_35 --shared --compiler-options -fPIC

Any idea how to solve this issue?

Many thanks in advance
d

i use fedora and not ubuntu, as i prefer rpm over debian; however, the differences should not be too significant

“when I link this library libgpu-mine.so from other cuda code I get this linker error:”

verify that the shared library is indeed in the particular folder, and make sure to export its path by means of an entry under /etc/ld.so.conf.d and running ld on the particular shared library
or, set the LD_LIBRARY_PATH environment variable, with the path to the shared library

and make sure your cuda libraries are also properly exported - again there should be an entry under /etc/ld/so.conf.d likely of the form /usr/local/cuda-x/lib64

I dont know if the problem exposed here was related to the latest version of the toolkit, but upgrading to nvcc 7.0 yielded a similar error for me:

CMakeFiles/Application.dir/./Application_intermediate_link.o: In function __cudaRegisterLinkedBinary_66_tmpxft_000073f4_00000000_16_cuda_device_runtime_compute_52_cpp1_ii_8b1a5d37': link.stub:(.text+0x44f): undefined reference to __fatbinwrap_66_tmpxft_000073f4_00000000_16_cuda_device_runtime_compute_52_cpp1_ii_8b1a5d37’

(no error when building with cuda-6.0 toolkit suite)

How to troubleshoot this kind of problem ?

Ok in fact I had to link with -lcudadevrt
Now it works

Same issue as Tobbey here, but linking with -lcudadevrt doesn’t seem to change anything. I’m using cuda 7 and I don’t recall ever receiving this error with 6.5.

Try placing the cuda shared library libgpu-mine.so before the objects that (you only think) reference it when linking, e.g. g++ -lgpu-mine -lcpu-mine main.o -lcudart -lcudadevrt -o myCudaProgram.exe