Re: Assistance required, exporting a class from a DLL
Alex Blekhman wrote:
Actually, if you use an unexported instantiation of a standard
container as a data member, then you won't see it exported, but
you will get C4251 warning (level 1) about such member.
However, if you use an unexported instantiation of a standard
container as a base class, then compiler will export everything
from this standard container. Also, you'll see the C4275 warning
(level 2).
Thanks, I wasn't aware that those two are different.
2. I know that I exported a class derived from
std::pair<unsigned,unsigned> from a library, and the compiler
actually exported not only symbols of the derived class but also
symbols of the baseclass. I personally consider that a bug, and
I believe it also isn't present in all MS compilers [...].
Why do you think it is a bug? Suppose client creates an instance
of the exported object. Now compiler must be able to call its
constructor, check availability and visibility of base class
contructior etc..
They probably could encapsulate all derived<-->base machinery in
methods of derived class, so only these methods would be exported.
However, they decided to export base class in its entirety and let
the clinet side compiler to make certain decisions. I see it as an
implementation detail, not a bug.
My problem is specifically that I have a DLL that exports a class derived
from pair<unsigned,unsigned>. In a program, I'm also using
pair<unsigned,unsigned> and that library. So, in the TUs that include the
library's header, it assumes the pair is imported from the lib, in other
TUs the template is instantiated as usual. This actually leads to linker
errors due to multiple definitions. If the linker was at least smart enough
to ignore the local instantiation of pair<> I might not even have noticed.
I then simply solved the problem by including the library's header in the
other TUs that used the pair, even though there is no real dependency on
that library. However, I'm afraid that won't be that easy once you have two
DLLs that (IMHO wrongly) export the same symbols. I haven't had that case
though and also didn't try if it leads to trouble.
BTW: what I don't get is the different treatment of members and baseclasses.
Similarly, it doesn't make sense to treat template classes differently.
cheers
Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Gesch??ftsf??hrer: Thorsten F??cking, Amtsgericht Hamburg HR B62 932