title: DLL and fully-specialized template class
body: <p>Environment: Visual Studio 9, C++ without managed extensions.</p>
  
  <p>I've got a third-party library which exports a fully-specialized template class <code>MyClass&lt;42&gt;</code> defined in MyClass.h. It gets compiled into a helper loader .lib and a .dll file. The .lib file contains compiled code for this specialization, and necessary symbols. The MyClass.h looks like this:</p>
  
  <pre><code>template&lt;UInt D&gt;
  class MyClass {
  public:
      MyClass() {...};
      virtual ~MyClass() {};
  }
  </code></pre>
  
  <p>Now I'd like to use this library. If I include the MyClass.h in a Client.cpp and then compile it, I'll get second copy of these symbols in the Client.obj file. I can get rid of these symbols by defining all the member of that specialization as "extern". My Client.cpp looks like this:</p>
  
  <pre><code>#include &lt;ThirdParty/MyClass.h&gt;
  
  extern template class MyClass&lt;42&gt;;
  extern template MyClass&lt;42&gt;::MyClass&lt;42&gt;();
  extern template MyClass&lt;42&gt;::~MyClass&lt;42&gt;();
  
  void MyFunction(MyClass&lt;42&gt;&amp; obj) {...}
  </code></pre>
  
  <p>The problem is that I cannot get rid of the virtual destructor this way. For the virtual destructor I get an almost standard LNK2005 error:</p>
  
  <pre><code>ThirdPartyd.lib(ThirdPartyd.dll) : error LNK2005:
      "public: virtual __thiscall MyClass&lt;42&gt;::~MyClass&lt;42&gt;(void)"
      (??1?$MyClass@$01@@@UAE@XZ) already defined in Client.obj
  </code></pre>
  
  <p>What should I do?</p>