c++ template instanciation and dlls on win32

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi,

I suspect that this question might not be related specifically to gcc
and is more related to the specifics of the way the win32 linking model
works but there are a few gcc-specific questions below.

Here is my sample code: 
http://www-sop.inria.fr/dream/personnel/Mathieu.Lacage/tmp.tar.gz

What this code shows is that, on ELF systems, both the library and the
main binary access the same Test<0>::Exec function instance and, thus,
the same local static variable instance. If you happen to run this code
on mingw (cygwin will work too), the main binary and the dll will access
different copies of the Test<0>::Exec function which means that they
access different versions of the local static variable instance, which
ends up breaking a large amount of my code.

So, the question is: can I make sure that only one instance of the Exec
function is ever stored in one of my binaries and then make sure that it
is exported and that everyone can access this instance ?

Before this, I had never used the gcc manual template instanciation
model so, I thought that it could help me. Naively, on Linux, I first
tried to recompile all code with -fno-implicit-templates but it looks
like this switch is ignored since all my object files which use the
template function Test<0>::Exec still contain a copy of the function.

So, the first question is: is there something magic I need to know about
-fno-implicit-templates ? Or maybe I misunderstood the purpose of that
switch ?

The second question is: if I can control the template instanciation
successfully and avoid multiple instanciations in multiple binaries, how
can I make sure that the single instanciation left is exported from my
binary on win32 and linux ? On win32, I suspect that all I need to do is
declspec it with the export flag. Am I right ?

Potentially, the approach I have attempted to follow to solve my problem
is just plain wrong: is there someone more knowledgable than me who
knows what I could do (beyond rewrite all my code which uses static
template methods with static local variables).

Mathieu


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux