title: Link error LNK2005 several CUDA files
body: <p>I got some problems with the error "Link error LNK2005 ... already defined". The files are as follows:</p>
  
  <pre><code>// File Bitmap4.cu
  #include "Bitmap4.h" // header
  #include "Bitmaps_cuda.h" // header with just the definitions of the kernels
  
  ..... // I call 3+2 kernel functions (3 in one method, 1 in another and 1 in another one)
  </code></pre>
  
  <p>Then I have this one:</p>
  
  <pre><code>// File Bitmap8.cu
  #include "Bitmap8.h" // header
  #include "Bitmaps_cuda.h" // the same as above
  
  ..... // I call 4 kernel functions (4 in the same method)
  </code></pre>
  
  <p>Then I have the kernel header:</p>
  
  <pre><code>#ifndef __BITMAPS_KERNEL__
  #define __BITMAPS_KERNEL__
  
  ......  // 9 kernels definitions
  
  #endif
  </code></pre>
  
  <p>And finally, I have this one:</p>
  
  <pre><code>// File Bitmaps_cuda.h
  #include &lt;cuda.h&gt;
  #include &lt;cuda_runtime.h&gt;
  #include &lt;device_launch_parameters.h&gt;
  #include &lt;device_functions.h&gt;
  #include &lt;stdio.h&gt;
  
  // Inside here there all the kernel functions that the files 
  // Bitmap4.cu and Bitmap8.cu are using
  </code></pre>
  
  <p>The problem is that, if i don't include the <strong>#include "Bitmaps_cuda.h"</strong> in one of the Bitmap*.cu, of course, the compiler will say that I missed the definitions of the kernels functions. I read a lot of posts and i already included the "Additional Dipendencies" and the required PATHs. The problems started when I added the file Bitmap8.cu with its relative kernels, because before that, the application was working properly. </p>
  
  <p>Anyway, those are the error that i have:</p>
  
  <pre><code>1&gt;Bitmap8.cu.obj : error LNK2005: "void * __cdecl big_random_block(int(?big_random_block@@YAPAXH@Z) already defined in Bitmap4.cu.obj
  1&gt;Bitmap8.cu.obj : error LNK2005: "int * __cdecl big_random_block_int(int(?big_random_block_int@@YAPAHH@Z) already defined in Bitmap4.cu.obj
  1&gt;Bitmap8.cu.obj : error LNK2005: "unsigned char __cdecl value(float,float,int(?value@@YAEMMH@Z) already defined in Bitmap4.cu.obj
  1&gt;Bitmap8.cu.obj : error LNK2005: "void * __cdecl start_thread(unsigned int(__stdcall*)(void *),void *)" (?start_thread@@YAPAXP6GIPAX@Z0@Z) already defined in Bitmap4.cu.obj
  1&gt;Bitmap8.cu.obj : error LNK2005: "void __cdecl end_thread(void *)"(?end_thread@@YAXPAX@Z) already defined in Bitmap4.cu.obj
  1&gt;Bitmap8.cu.obj : error LNK2005: "void __cdecl destroy_thread(void *)"(?destroy_thread@@YAXPAX@Z) already defined in Bitmap4.cu.obj
  1&gt;Bitmap8.cu.obj : error LNK2005: "void __cdecl wait_for_threads(void * const *,int)"(?wait_for_threads@@YAXPBQAXH@Z) already defined in Bitmap4.cu.obj
  1&gt;Bitmap8.cu.obj : error LNK2005: "void __cdecl__device_stub__Z14float_to_colorPhPKf(unsigned char *,float const *)"(?__device_stub__Z14float_to_colorPhPKf@@YAXPAEPBM@Z) already defined in Bitmap4.cu.obj
  1&gt;Bitmap8.cu.obj : error LNK2005: "void __cdecl float_to_color(unsigned char *,float_const *)" (?float_to_color@@YAXPAEPBM@Z) already defined in Bitmap4.cu.obj
  1&gt;Bitmap8.cu.obj : error LNK2005: "void __cdecl__device_stub__Z14float_to_colorP6uchar4PKf(struct uchar4 *,float const *)"(?__device_stub__Z14float_to_colorP6uchar4PKf@@YAXPAUuchar4@@PBM@Z) already defined in Bitmap4.cu.obj
  1&gt;Bitmap8.cu.obj : error LNK2005: "void __cdecl float_to_color(struct uchar4 *,float_const *)" (?float_to_color@@YAXPAUuchar4@@PBM@Z) already defined in Bitmap4.cu.obj
  
  1&gt;C:\Users\dberdin\documents\visual studio 2010\Projects\gpuSPAM\Debug\gpuSPAM.exe : fatal error LNK1169: one or more multiply defined symbols found
  </code></pre>
  
  <p>I tried different solutions but with any results.</p>
  
  <p>Thank you in advance!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>On the website (<a href="http://msdn.microsoft.com/en-us/library/72zdcz6f.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/72zdcz6f.aspx</a>) i found that one of the causes of those errors is:<br>
  <em>- An absolute is defined twice, with a different value in each definition.</em><br>
  Well, actually, as i wrote in the bottom, i have these kind of definetions, but i can't do differently. Any idea how to solve it ?</p>
  
  <p>Thank you again in advance</p>