This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: duplicate singleton on Windows-platform
- From: Michael Hennebry <hennebry at web dot cs dot ndsu dot nodak dot edu>
- To: Chris Bielow <bielow at mi dot fu-berlin dot de>
- Cc: <binutils at sourceware dot org>
- Date: Wed, 6 Feb 2008 16:37:41 -0600 (CST)
- Subject: Re: duplicate singleton on Windows-platform
On Wed, 6 Feb 2008, Chris Bielow wrote:
> Hi,
>
> I'm having trouble creating a "real" singleton on Windows (MinGW
> Binutils 2.18) when linking my the executable against the shared version
> my library (all C++). Under Linux everything is fine.
> The Singleton is a static member of template class.
>
> ------------- Factory.h ----------------
> template<typename FactoryProduct> Factory<FactoryProduct>*
> Factory<FactoryProduct>::instance_ptr_ = 0;
>
> ----------- END Factory.h ---------
>
> The Factory.h header is included in some of the classes (**) that are
> compiled into the shared library.
If Factory.h is included in more the one C++ file,
I think your code is illegal.
It defines a variable twice.
> Now, if I write a test program that uses this library, there seem to be
> multiple instances, as I get :
>
> INITIALIZING ...
> INITIALIZING ...
>
> , which does NOT happen when linking the executable with the static
> version of the library.
> btw: The test program also includes the Factory.h header, because it
> contains something like:
> ----------- Test.Cpp -----------
> DataReducer* p = Factory<DataReducer>::create("max_reducer");
> ----------- END Test.Cpp -----------
> Any ideas why that happens?
Some sets of build tools are less forgiving than others.
The others did a better job of fixing your error.
--
Michael hennebry@web.cs.ndsu.NoDak.edu
"Those parts of the system that you can hit with a hammer (not advised)
are called Hardware; those program instructions that you can only
curse at are called Software."