title: Duplicate symbol issue with C headers
body: <p>This is my first time tackling a CUDA project that's slightly more complex than the simple write-single-source-file-and-compile routine. As expected, I'm facing some issues with C headers, namely duplicated symbols.</p>
  
  <p>According to the linker, conflicts arise over the inclusion of the following header file in multiple <code>.cu</code> files:</p>
  
  <p><strong>env_vars.h</strong></p>
  
  <pre><code>#ifndef ENV_VARS_H_
  #define ENV_VARS_H_
  
  /*** GLOBAL VARIABLES ***/
  unsigned int h_n_osc;
  __device__ unsigned int d_n_osc;
  
  /*** CONSTANTS ***/
  const double OMEGA_0 = 6.447421494058077e+09;
  
  /* other constants defined in the middle */
  
  #endif
  </code></pre>
  
  <p><strong>multigpu.cu</strong></p>
  
  <pre><code>#include "env_vars.h"
  /* assigns h_n_osc */
  </code></pre>
  
  <p><strong>adm_matrix.cu</strong></p>
  
  <pre><code>#include "env_vars.h"
  /* uses h_n_osc */
  </code></pre>
  
  <p>Building the project in Nsight Eclipse Edition results in the linker complaining about the <code>h_n_osc</code> variable being defined twice:</p>
  
  <pre><code>duplicate symbol _h_n_osc in:
      ./adm_matrix.o
      ./multigpu.o
  ld: 1 duplicate symbol for architecture x86_64
  </code></pre>
  
  <p>Searching through the Internet, I've realized that moving the declaration of the <code>h_n_osc</code> variable to <code>multigpu.cu</code> and re-declaring it as an <code>extern</code> variable in <code>adm_matrix.cu</code> (and wherever I might need it later) solves the problem, <em>which in fact it does</em>.</p>
  
  <p>Problem solved, but I'd like to take a deeper look into this:</p>
  
  <ol>
  <li>Why doesn't the linker complain about the <code>d_n_osc</code> variable as well? And why are the constants (such as <code>OMEGA_0</code>) equally not a problem?</li>
  <li>Does this mean that it is not possible to place global variables in header files?</li>
  <li>What puzzles me most is that a number of sources over the Internet state that duplicated symbol errors should happen only when the header file contains a <em>definition</em> of the variable, while its simple <em>declaration</em> shouldn't constitute a problem. The reason I have a hard time believing this is that I'm facing the issue even though my header only contains a declaration! Am I missing something?</li>
  </ol>
  
  <p>Thanks in advance for your patience, folks!</p>