title: Why does compiler add inlined class methods to lib?
body: <p>Consider a class that belongs to a project linked to dynamic library (foo.dll), with foo.lib generated on the side too:</p>
  
  <pre><code>class IMP_EXP_DIRECTIVE_MACRO Foo
  {
       void bar()
       {
           // do something
       }
   };
  </code></pre>
  
  <p>Then there is also another project bar (generating static library bar.lib) that includes this class. The project does not link with foo.</p>
  
  <p>Finally there's an application project (resulting in .exe), which links with both foo.lib and bar.lib.
  When it does, linker shouts with LNK2005  error that <code>Foo::bar</code> is already defined in both foo.lib (which is good) and in bar.lib, which is unexpected and weird.</p>
  
  <p>When treating bar.lib with dumpbin.exe /SYMBOLS according to <a href="https://docs.microsoft.com/en-us/cpp/build/reference/symbols?view=vs-2017" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/cpp/build/reference/symbols?view=vs-2017</a> output shows that <code>Foo::bar</code> is indeed defined in foo.lib (!). That is strange, because according to this brilliant <a href="https://stackoverflow.com/a/4955288">https://stackoverflow.com/a/4955288</a> answer, any member function that's declared and defined in the body of a class is implicitly inlined, therefore doesn't cause ODR problems.</p>
  
  <p>Finally, the most interesting part. When moving <code>Foo::bar</code> definition to .cpp file and leaving only method's declaration in a class body, problem disappears.</p>
  
  <p>Why is that so? Any idea what is being done wrong?
  I think I've read the whole internet about this topic and tried all various VS configuration switches, but only moving definition to .cpp helps.
  In principle I can eventually do it, but it doesn't seem like a proper solution to the issue.</p>
  
  <p>Environment is: Visual Studio 10.</p>
  
  <p><strong>edit:</strong><br>
  IMP_EXP_DIRECTIVE_MACRO is set to:<br>
  "__declspec(dllexport)", when building foo.dll<br>
  "", when building bar</p>
  
  <p><strong>edit 2:</strong><br>
  Problem is also gone, when added a preprocessor flag to compiling bar.lib that causes <code>class __declspec(dllimport) Foo</code> usage instead of <code>class Foo</code>.<br>
  Is that the right way to go?</p>