title: Exporting classes containing `std::` objects (vector, map etc.) from a DLL
body: <p>I'm trying to export classes from a DLL that contain objects such as <code>std::vectors</code> and <code>std::strings</code> - the whole class is declared as DLL export through:</p>
  <pre><code>class DLL_EXPORT FontManager {
  </code></pre>
  <p>The problem is that for members of the complex types I get this warning:</p>
  <blockquote>
  <pre><code>warning C4251: 'FontManager::m__fonts' : class 'std::map&lt;_Kty,_Ty&gt;' needs to have dll-interface to be used by clients of class 'FontManager'
        with
        [
            _Kty=std::string,
            _Ty=tFontInfoRef
        ]
  </code></pre>
  </blockquote>
  <p>I'm able to remove some of the warnings by putting the following forward class declaration before them even though I'm not changing the type of the member variables themselves:</p>
  <pre><code>template class DLL_EXPORT std::allocator&lt;tCharGlyphProviderRef&gt;;
  template class DLL_EXPORT std::vector&lt;tCharGlyphProviderRef,std::allocator&lt;tCharGlyphProviderRef&gt; &gt;;
  std::vector&lt;tCharGlyphProviderRef&gt; m_glyphProviders;
  </code></pre>
  <p>Looks like the forward declaration &quot;injects&quot; the <code>DLL_EXPORT</code> for when the member is compiled but is it safe?<br />
  Does it really change anything when the client compiles this header and uses the <code>std::</code> container on his side?<br />
  Will it make all future uses of such a container <code>DLL_EXPORT</code> (and possibly not inline)?<br />
  And does it really solve the problem that the warning tries to warn about?</p>
  <p>Is this warning anything I should be worried about or would it be best to disable it in the scope of these constructs?<br />
  The clients and the DLL will always be built using the same set of libraries and compilers and those are header only classes...</p>
  <p>I'm using Visual Studio 2003 with the standard STD library.</p>
  <hr />
  <h3>Update</h3>
  <p>I'd like to target you more though as I see the answers are general and here we're talking about std containers and types (such as <code>std::string</code>) - maybe the question really is:</p>
  <p>Can we disable the warning for standard containers and types available to both the client and the DLL through the same library headers and treat them just as we'd treat an <code>int</code> or any other built-in type? (It does seem to work correctly on my side)<br />
  If so would should be the conditions under which we can do this?</p>
  <p>Or should maybe using such containers be prohibited or at least ultra care taken to make sure no assignment operators, copy constructors etc will get inlined into the DLL client?</p>
  <p>In general I'd like to know if you feel designing a DLL interface having such objects (and for example using them to return stuff to the client as return value types) is a good idea or not and why, I'd like to have a &quot;high level&quot; interface to this functionality...<br />
  Maybe the best solution is what Neil Butterworth suggested - creating a static library?</p>