title: Circular include statements leading to link error
body: <p>I have a large project (20+ files) but I managed to set up this small example which recreates my problem. Essentially I have one file (<code>A.cpp</code>) including a second file (<code>B.cpp</code>), but that second file needs several of the variables and functions from the first file. Observe:</p>
  
  <p><strong>A.h:</strong></p>
  
  <pre><code>#ifndef _A_H_
  #define  _A_H_
  static void foo(int _something);
  #endif // #ifndef _A_H_
  </code></pre>
  
  <p><strong>A.cpp:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "A.h"
  #include "B.h"
  
  using namespace std;
  
  static void foo(int _something)
  {
     cout &lt;&lt; _something &lt;&lt; "\n";
  }
  
  int main(int argc, char *argv[])
  {
     B *b;
  
     foo ( 123 ); // So we don't get that pesky defined-not-used warning
     b = new B ();
     b-&gt;display ( 123 );
  }
  </code></pre>
  
  <p><strong>B.h:</strong></p>
  
  <pre><code>#ifndef _B_H_
  #define  _B_H_
  #include "A.h"
  
  class B
  {
     public:
        B();
        ~B();
        void display ( int x );
  };
  #endif // #ifndef _B_H_
  </code></pre>
  
  <p><strong>B.cpp:</strong></p>
  
  <pre><code>#include "B.h"
  
  void B::display ( int x )
  {
     foo ( x );
  }
  </code></pre>
  
  <p>And I am compiling it like so, <code>g++ -Wall A.cpp B.cpp -o main</code> but then I get this error:</p>
  
  <pre><code>A.h:3:13: warning: ‘void foo(int)’ used but never defined [enabled by default]
  /tmp/ccFwfZa6.o: In function `main':
  A.cpp:(.text+0x54): undefined reference to `B::B()'
  /tmp/ccM8SNBK.o: In function `B::display(int)':
  B.cpp:(.text+0xd): undefined reference to `foo(int)'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>I can tell it's a link error, but I can't tell why I am getting that error.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>In my original code I am <em>still</em> getting an error, this time it's about the multiple definition of an integer, here is the error I am getting:</p>
  
  <pre><code>B.o:(.bss+0x4): multiple definition of `some_var'
  A.o:(.bss+0x4034): first defined here
  collect2: error: ld returned 1 exit status
  make: *** [main] Error 1
  </code></pre>
  
  <p>and I am creating the variable <code>some_var</code> like so</p>
  
  <p><strong>A.h:</strong></p>
  
  <pre><code>#ifndef _A_H_
  #define  _A_H_
  static void foo(int _something);
  int some_var;
  #endif // #ifndef _A_H_
  </code></pre>
  
  <p>How is it possible that <code>some_var</code> would get defined more than once when I have those conditional guards?</p>