title: Static class members in shared library
body: <p>I have a class like</p>
  
  <pre><code>class K {
    static int a;
    static int b;
  }
  </code></pre>
  
  <p>I would like to create a shared library (dll) containing this class <code>K</code>. In a cpp file compliled in the library I call</p>
  
  <pre><code>int K::a = 0;
  int K::b = 0;
  </code></pre>
  
  <p>to instantiate the static variables. The dll does compile without errors, but when I use the library, I get the unresolved external symbol error for the members <code>K::a</code> and <code>K::b</code>. In the main program where I want to use it, I include the same header with the declaration of the class <code>K</code>, the only difference is that for the library I use <code> class __declspec( dllexport ) K { ... } </code> and for the main program <code>class K { ... } </code></p>
  
  <p>Probably I am doing more than one mistake so my questions would be, how can I</p>
  
  <ul>
  <li>tell the linker to share the static member class in the library?</li>
  <li>use the static class members instantiated in the library in the main program?</li>
  </ul>
  
  <p>PS. I use Visual Studio 2008...</p>