title: inconsistent dll linkage & definition of dllimport static data member not allowed
body: <p>Assuming I have these two files:</p>
  
  <p><em>Header.h</em></p>
  
  <pre><code>class DLL ExportClass{
  public:
    ExportClass();
    static int test;
  };
  </code></pre>
  
  <p><em>Source.cpp</em></p>
  
  <pre><code>#ifdef EXPORT
      #define DLL __declspec(dllexport)
  #else
      #define DLL __declspec(dllimport)
  #endif
  
  #include "Header.h"
  
  int ExportClass::test = 0;
  ExportClass::ExportClass(){
  }
  </code></pre>
  
  <p>And I won't define <code>EXPORT</code> (to import a already exported class with a <code>static</code> member), why do I get these warnings:</p>
  
  <pre><code>1&gt;source.cpp(11): warning C4273: 'test' : inconsistent dll linkage
  1&gt;          header.h(4) : see previous definition of 'public: static int ExportClass::test'
  1&gt;source.cpp(13): warning C4273: 'ExportClass::ExportClass' : inconsistent dll linkage
  1&gt;          header.h(3) : see previous definition of '{ctor}'
  </code></pre>
  
  <p>And this error:</p>
  
  <pre><code>1&gt;source.cpp(11): error C2491: 'ExportClass::test' : definition of dllimport static data member not allowed
  </code></pre>
  
  <p>If I define <code>EXPORT</code> it works. I kind of understand the warnings, but I thought, that the static variable and the ctor could be ignored by the compiler, because the whole class is declared as <code>__declspec(dllimport)</code> anyway. I want to use the same codebase for the <code>__declspec(dllexport)</code> and <code>__declspec(dllimport)</code> - but it seems the compiler stll tries to define these symbols that are marked as <code>__declspec(dllexport)</code> in their declaration. What is the common practice to solve this problem?</p>