I am trying to export classes from DLLs containing objects such as std :: vectors and std :: strings - the whole class is declared as a dll export via:
class DLL_EXPORT FontManager {
The problem is that for members of complex types, I get this warning:
warning C4251: 'FontManager :: m__fonts': class 'std :: map <_Kty, _Ty>' must have a dll interface that will be used by clients of the 'FontManager' class with [_Kty = std :: string, _Ty = tFontInfoRef]
I can remove some warnings by putting the following class declaration in front of them, even if I do not change the type of the member variables themselves:
template class DLL_EXPORT std::allocator<tCharGlyphProviderRef>; template class DLL_EXPORT std::vector<tCharGlyphProviderRef,std::allocator<tCharGlyphProviderRef> >; std::vector<tCharGlyphProviderRef> m_glyphProviders;
It seems that the front declaration injects DLL_EXPORT when the member compiles, but is it safe? Does this really change something when the client compiles this header and uses the std container on its side? Will all future uses of such a DLL_EXPORT container (and possibly not inline?) Do this? And does it really fix the issue the warning warns about?
Is this warning something I have to worry about, or would it be better to disable it as part of these constructs? Clients and dlls will always be built using the same set of libraries and compilers, and these are header-only classes ...
I am using Visual Studio 2003 with the standard STD library.
---- Update ----
I would like to target you more, because, as I see, the answers are general, and here we are talking about std containers and types (for example, std :: string) - maybe the question is really like this:
Is it possible to disable the warning for standard containers and types available to both the client and the DLL through the same library headers, and treat them the same way as we will consider an int or any other built-in type? (It seems he is working correctly on my side.) If these were the conditions under which we can do this?
Or maybe the use of such containers is forbidden, or at least very carefully to make sure that no assignment operators, copy constructors, etc. will not be included in the dll client?
In general, I would like to know if you feel that the design of a dll interface in which such objects (and, for example, using them to return material to the client as return types) is a good idea or not, and why would I for example, have a "high level" interface for this functionality ... perhaps the best solution is what Neil Butterworth suggested - creating a static library?