title: Calling static C++ method from C gives undefined reference when compiled
body: <p>Here's a simple set of files that reproduce the problem I'm having:</p>
  
  <p>c.h:</p>
  
  <pre><code>void dummy();
  </code></pre>
  
  <p>c.cpp:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  extern "C" {
  #include "c.h"
  }
  
  class Bubu {
  public:
    static Bubu *getInstance() {
      if (_instance == NULL) {
        _instance = new Bubu;
      }
      return _instance;
    }
  
  private:
    static Bubu *_instance;
  };
  
  Bubu *_instance = NULL;
  
  void dummy() {
    printf("bubu called\n");
    Bubu *ptr = Bubu::getInstance();
  }
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>extern "C" {
  #include "c.h"
  }
  
  int main() {
    dummy();
    return 0;
  }
  </code></pre>
  
  <p>When I compile I get this:</p>
  
  <pre><code>g++ -W -Wall -c c.cpp -o c.o
  c.cpp: In function ‘int bubu()’:
  c.cpp:24: warning: unused variable ‘ptr’
  g++ -W -Wall main.cpp c.o -o main
  c.o: In function `Bubu::getInstance()':
  c.cpp:(.text._ZN4Bubu11getInstanceEv[Bubu::getInstance()]+0x7): undefined reference to `Bubu::_instance'
  c.cpp:(.text._ZN4Bubu11getInstanceEv[Bubu::getInstance()]+0x1d): undefined reference to `Bubu::_instance'
  c.cpp:(.text._ZN4Bubu11getInstanceEv[Bubu::getInstance()]+0x24): undefined reference to `Bubu::_instance'
  collect2: ld returned 1 exit status
  make: *** [main] Error 1
  Compilation exited abnormally with code 2 at Tue Dec 15 09:15:21
  </code></pre>
  
  <p>I've seen the answer to other similar questions but there the problem is either a missing Bubu:: when calling the static method or lack of initialisation of the static member outside the class declaration or missing the <em>extern "C"</em> construct. I'm fairly certain that I'm not making those mistakes ... I'm definitely making other(s).
  Can you please explain what's going on?</p>