title: cuda shared library linking: undefined reference to cudaRegisterLinkedBinary
body: <p>Goal:  </p>
  
  <ol>
  <li>create a shared library containing my CUDA kernels that has a CUDA-free wrapper/header.</li>
  <li>create a <code>test</code> executable for the shared library.</li>
  </ol>
  
  <p>Problem</p>
  
  <ol>
  <li>shared library <code>MYLIB.so</code> seems to compile fine. (no problem).</li>
  <li>Error in linking: </li>
  </ol>
  
  <p><code>./libMYLIB.so: undefined reference to __cudaRegisterLinkedBinary_39_tmpxft_000018cf_00000000_6_MYLIB_cpp1_ii_74c599a1</code></p>
  
  <p>simplified makefile:</p>
  
  <pre><code>libMYlib.so :  MYLIB.o
      g++  -shared  -Wl,-soname,libMYLIB.so  -o libMYLIB.so    MYLIB.o  -L/the/cuda/lib/dir  -lcudart
  
  
  MYLIB.o : MYLIB.cu   MYLIB.h
      nvcc  -m64   -arch=sm_20 -dc  -Xcompiler '-fPIC'  MYLIB.cu  -o  MYLIB.o  -L/the/cuda/lib/dir  -lcudart
  
  
  test : test.cpp  libMYlib.so
          g++   test.cpp  -o test  -L.  -ldl -Wl,-rpath,.   -lMYLIB  -L/the/cuda/lib/dir  -lcudart
  </code></pre>
  
  <hr>
  
  <p>indeed</p>
  
  <p><code>nm  libMYLIB.so</code>  shows that <strong>all</strong> CUDA api functions are "undefined symbols":</p>
  
  <pre><code>         U __cudaRegisterFunction
           U __cudaRegisterLinkedBinary_39_tmpxft_0000598c_00000000_6_CUPA_cpp1_ii_74c599a1
           U cudaEventRecord
           U cudaFree
           U cudaGetDevice
           U cudaGetDeviceProperties
           U cudaGetErrorString
           U cudaLaunch
           U cudaMalloc
           U cudaMemcpy
  </code></pre>
  
  <p>So CUDA somehow did not get linked to the shared library  MYLIB.so
  What am I missing?</p>
  
  <hr>
  
  <p>CUDA did not even get linked to the object file somehow:</p>
  
  <p><code>nm  MYLIB.o</code></p>
  
  <pre><code>         U __cudaRegisterFunction
           U __cudaRegisterLinkedBinary_39_tmpxft_0000598c_00000000_6_CUPA_cpp1_ii_74c599a1
           U cudaEventRecord
           U cudaFree
           U cudaGetDevice
           U cudaGetDeviceProperties
           U cudaGetErrorString
           U cudaLaunch
           U cudaMalloc
           U cudaMemcpy
  </code></pre>
  
  <p>(same as above)</p>