title: Exporting global variables from DLL
body: <p>I'm trying to export a global variable from a DLL.</p>
  
  <p>Foo.h</p>
  
  <pre><code>class Foo
  {
  public:
      Foo()
      {}
  };
  
  #ifdef PROJECT_EXPORTS
      #define API __declspec(dllexport)
  #else
      #define API __declspec(dllimport)
  #endif
  
  API const Foo foo;
  </code></pre>
  
  <p>Foo.cpp</p>
  
  <pre><code>#include "Foo.h"
  
  const Foo foo;
  </code></pre>
  
  <p>When I compile the above code, Visual Studio complains:</p>
  
  <p>foo.cpp(3) : error C2370: 'foo' : redefinition; different storage class
  1>        foo.h(14) : see declaration of 'foo'</p>
  
  <p>If I use:</p>
  
  <pre><code>external const Foo foo;
  </code></pre>
  
  <p>in Foo.h the compiler is happy but then the DLL does not export the symbol. I've managed to export functions with problems, but variables don't seem to work the same way... Any ideas?</p>