title: How to separate the kernel file CUDA with the main .cpp file
body: <p>When I build the code with kernelAdd() function and main() function in the same file mainFunc.cu, it's ok.</p>
  
  <p>But when I separate the kernelAdd() function in the kernelAdd.cu file and the main file in main.cpp file, it's built with the 2 errors:</p>
  
  <p>"error C2065: 'add' : undeclared identifier"</p>
  
  <p>and "error C2059: syntax error : '&lt;'"</p>
  
  <p>I built them in Visual Studio 2008 and Cuda v5.0.</p>
  
  <p>And how do I correct its errors?</p>
  
  <p>Thanks!</p>
  
  <p>kernelAdd.cu</p>
  
  <pre><code>__global__ void add(int a, int b, int *c) {
  *c = a + b;
  }
  </code></pre>
  
  <p>mainFunc.cpp</p>
  
  <pre><code>#include "cuda_runtime.h"
  #include "device_launch_parameters.h"
  #include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  
  int main(void) {
  
  int c;
  int *devC;
  
  cudaMalloc((void**) &amp;devC, sizeof(int));
  add&lt;&lt;&lt;1,1&gt;&gt;&gt;(2,7,devC);
  cudaMemcpy(&amp;c, devC, sizeof(int), cudaMemcpyDeviceToHost);
  
  printf("2+7=%d\n", c);
  
  cudaFree(devC);
  
  getch();
  return 0;
  }
  </code></pre>