title: How do I properly declare extern variables in a C++ header file?
body: <p>I currently have a few header files. One named &quot;globalVar.h&quot; for global variables, one named &quot;generate.h&quot; for variables having to do with generation, and I have one named &quot;screen.h&quot; for variables having to do with the screen. Whenever I include these and run the file I get an error exactly like this one for each of my variables:</p>
  <pre><code>globalVar.h:7:19: warning: 'y' initialized and declared 'extern'
   extern int x = 1, y = 1; // player coordinates
  </code></pre>
  <p>Why is this happening? For this example, here's the code for the &quot;globalVar.h&quot; header:</p>
  <pre><code>#ifndef GLOBALVAR_H
  #define GLOBALVAR_H
  
  #include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  
  extern int x = 1, y = 1; // player coordinates
  extern int health = 100; // player health
  extern int player = '@'; // player symbol
  
  extern int gX, gY; // goblin coordinates
  extern int health = 100; // goblin health
  extern int goblin = 'G'; // goblin symbol
  
  #endif
  </code></pre>
  <p>Am I doing something wrong? Surely I am because this makes sense to me, but I don't really know how header files work.</p>
  <p>Anyone have any ideas?</p>