* Win32 issues with Templates and Libs *
Walter Bright
newshound at digitalmars.com
Tue Feb 20 01:46:52 PST 2007
The problem is that one of two kinds of COMDAT sections can be generated:
1) Only one COMDAT with a particular name may appear
2) Any number of COMDATs with the same name may appear, pick one and
discard the others
Instantiating a template produces a COMDAT section. Since multiple
modules may instantiate a template with the same arguments, without
knowing about each other, option (2) is used.
When a module is put into a library, a dictionary is created for the
library, essentially an associative array of object modules indexed by
symbol names. COMDATs of option (1) get put into the dictionary, ones of
option (2) do not. Why not? Because if there's more than one of (2),
which object module do you pull in? No way to tell.
Thus, the problem you're seeing. The solution is:
1) have another global in module test that gets pulled in, thus also
pulling the COMDAT along with it, and resolving the symbol.
2) explicitly link in module test
So, you might ask, why not just regenerate the template instantiation
every time you use it? Because it would lead to a lot of object file bloat.
More information about the Digitalmars-d
mailing list