title: Dll import/export
body: <p>I have inherited a Linux project that I need to port to Windows and Visual Studio. I have setup the same project structure as was the case in Linux but I find the structure a bit strange (maybe it is all good in Linux) and I believe that's what's causing the LNK4217 (locally defined symbol 'symbol' imported in function 'function') and C4273 ('function' : inconsistent DLL linkage) warnings I receive. I would like some advice on how to re-structure the project or change the code to avoid these warnings. Basically this is what I have:</p>
  
  <ul>
  <li>Dll project called Foo</li>
  <li>Dll project called Bar (depends on the Foo dll)</li>
  </ul>
  
  <p>The part that I find strange and what I believe causes the LINK4217 and C4273 warnings is that both the Foo and Bar library contain the header and source file for the class <code>MyClass</code> (the warnings mention this class):</p>
  
  <pre><code>//MyClass.h
  class BAR_API MyClass
  {
      //Methods etc.
  }
  </code></pre>
  
  <p>Where <code>BAR_API</code> is defined as <code>__declspec(dllexport)</code> in the Bar library while in the Foo library it is <code>__declspec(dllimport)</code> according to:</p>
  
  <pre><code>#ifdef BAR_EXPORTS
  #define BAR_API __declspec(dllexport)
  #else
  #define BAR_API __declspec(dllimport)
  #endif
  </code></pre>
  
  <p>How do you propose I change this? Would it help to move MyClass to its own library and have Foo and Bar include it or change so that <code>BAR_API</code> is defined as nothing instead of <code>__declspec(dllimport)</code> in the Foo library?</p>