Farid Zaripov wrote:
From: Martin Sebor [mailto:[EMAIL PROTECTED]
To: [email protected]
Subject: Re: svn commit: r627648 - in /stdcxx/trunk/include: ./ loc/ rw/
I'm not sure I understand the problem. Is it because we declare
some explicit template instantiations when building the library
as
extern template __declspec(dllexport) void foo<int>();
Yes. Here the __declspec(dllexport) attribute leads to instantiating of the template class or function,
but extern keyword tells to not instantiate, because the template will be
instantiated in the another module.
And the compiler doesn't know what to do: instantiate template in current
module or not. I see that MSVC
prefer __declspec(dllexport) and instantiates the template. So in example the
classes string and wstring
are instantiated in every .cpp file, where <string> is included. Actually this
is my assumption ans I don't
know exactly whether is true on not. But after this patch the size of the
object files has reduced (the size
of the resulting .dll in shared builds is not changed).
I see. So __declspec(dllexport) is supposed to go with defintions
while extern template (only) with declarations.
I think the problem is that we seem to use __declspec(dllexport)
on both declarations and definitions, and while that's tolerated
for declarations of ordinary functions and classes the compiler
has a small cow when we apply it to extern template kind of
declarations.
Do you see a way to set things up so that we can still have just
_RWSTD_EXPORT and use it without triggering this warning?
Martin
From MSDN:
--------------
Error Message
'<identifier>' : '__declspec(dllexport)' and 'extern' are incompatible on an
explicit instantiation
The explicit template instantiation named <identifier> is modified by both the
__declspec(dllexport) and extern keywords. However, these keywords are mutually
exclusive. The __declspec(dllexport) keyword means instantiate the template class,
while the extern keyword means do not automatically instantiate the template class.
--------------
Why does this happen, and doesn't the problem affect ordinary
classes or functions as well? I.e., wouldn't either of the two
declarations below be a problem?
extern __declspec(dllexport) void foo();
__declspec(dllexport) void foo();
These declarations both are the same thing.
Farid.