title: Dynamic Parallelism - undefined reference to __cudaRegisterLinkedBinary linking error while compiling - separate compilation
body: <p>I got a problem when I try to compile a simple code there are C++ and Cuda code compile in a separated way.</p>
  
  <p>Here's my code</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include "file.cuh"
  
  int main( void )
  {
       test();
       return 0;
  }
  </code></pre>
  
  <p>file.cuh:</p>
  
  <pre><code>void test( void );
  </code></pre>
  
  <p>file.cu:</p>
  
  <pre><code>#include &lt;cuda.h&gt;
  #include &lt;cuda_runtime.h&gt;
  #include &lt;cstdio&gt;
  
  #include "file.cuh"
  
  __global__ void printId( void )
  {
      printf("Hello from block %d \n", blockIdx.x);
  }
  
  __global__ void DynPara( void )
  {
      dim3 grid( 2, 1, 1 );
      dim3 block( 1, 1, 1 );
  
      printId&lt;&lt;&lt; grid, block &gt;&gt;&gt;();
  }
  
  void test( void )
  {
      dim3 grid( 1, 1, 1 );
      dim3 block( 1, 1, 1 );
  
      dynPara&lt;&lt;&lt; grid, block &gt;&gt;&gt;();
  }
  </code></pre>
  
  <p>I compile with:</p>
  
  <pre><code>nvcc -arch=sm_35 -lcudadevrt -rdc=true -c file.cu
  g++ file.o main.cpp -L&lt;path&gt; -lcudart
  </code></pre>
  
  <p>And here's the error while compiling:</p>
  
  <pre><code>file.o: In function `__sti____cudaRegisterAll_39_tmpxft_00005b2f_00000000_6_file_cpp1_ii_99181f96()':
  tmpxft_00005b2f_00000000-3_file.cudafe1.cpp:(.text+0x1cd): undefined reference to `__cudaRegisterLinkedBinary_39_tmpxft_00005b2f_00000000_6_file_cpp1_ii_99181f96'
  </code></pre>
  
  <p>os: Red Hat
  card: K20x</p>
  
  <p>Any idea?</p>
  
  <p>Thanks</p>