Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What does this VC7 warning mean?

243 views
Skip to first unread message

Eran Kampf

unread,
Oct 6, 2001, 2:02:00 PM10/6/01
to
I defined a hash_map variable in a class which is exported from a DLL. I get
this warning when compiling:

c:\Dev\Projects\Belief\Source\Kernel\BlfKernelServer.h(27): warning C4251:
'Blf::KernelServer::m_DllList' :
class 'std::hash_map<_Kty,_Ty,_Tr,_Alloc>' needs to have dll-interface to be
used by clients of class 'Blf::KernelServer' with
[
_Kty=int,
_Ty=char *,
_Tr=std::hash_compare<int,std::less<int>>,
_Alloc=std::allocator<std::pair<const int,char *>>
]


Can anyone explain what does this mean?


Doug Harrison [MVP]

unread,
Oct 6, 2001, 9:12:23 PM10/6/01
to
Eran Kampf wrote:

I always disable this warning, which is usually spurious. The compiler
will instantiate the template when compiling code that uses it, so if
you don't mind each dynamically linked component having its own copy
of the generated template code, you should be fine. If you would like
to share one copy among all the dynamically linked components, you'll
need to explicitly instantiate the specializations you need and export
them from some common DLL everybody links to. For example, this is
what MS does with basic_string<char>, basic_string<wchar_t>, and other
specializations, which you'll find in msvcp60.dll (for VC6, anyway).

As for what the warning is trying to say, imagine that hash_map wasn't
a template, its (non-exported) code was contained entirely in your
DLL, and your Blf::KernelServer class defined some inline functions
which used hash_map functions. Then your DLL "clients" would not be
able to use those inline functions, because they would be instantiated
in the context of the client, and the hash_map functions they use
aren't available to the client. But this doesn't apply when hash_map
is a template for the reasons given above.

--
Doug Harrison [VC++ MVP]
Eluent Software, LLC
http://www.eluent.com
Tools for Visual C++ and Windows

0 new messages