Re: static variables discarded by the VS.NET2003 linker
- From: Ulrich Eckhardt <eckhardt@xxxxxxxxxxxxxx>
- Date: Thu, 22 Feb 2007 11:37:57 +0100
bdachev@xxxxxxxxx wrote:
In general the problem with VS.NET 2003 linker is that it will discard
an object file containing definitions of global variables of any type/
class if nothing else in this file is referenced by other files in the
project.
Now I have the following case. In given source file I have definitions
of several global variables that in contructor register itself in
another global container object. Later in code any of these variables
would be accessed via that global container. But what actually happens
is that the linker decides to discard the object files and instances
of these global variables are never created and registered in the
container.
Same problem here. I simply added artificial references to the code,
prefixed with a comment why it is there. I personally consider the
behaviour broken in an unfortunate way, but I guess not sorting out reverse
references would eventually lead to that much bloat that sorting out things
wouldn't make sense at all. Also, sometimes you have two implementations X
in the final link and explicitly want that only the first is taken, i.e. to
override the second. If X now had any back references, you would be stuck
because both have back references and the linker would thus try to include
both.
I'm not sure if that was with MS' compiler/linker or GCC, but I seem to
remember that you could add a property to an object telling the linker not
to discard it. Try looking into the docs for __declspec() and tell me if
you find anything. ;)
Uli
.
- Follow-Ups:
- Re: static variables discarded by the VS.NET2003 linker
- From: bdachev
- Re: static variables discarded by the VS.NET2003 linker
- References:
- static variables discarded by the VS.NET2003 linker
- From: bdachev
- static variables discarded by the VS.NET2003 linker
- Prev by Date: static variables discarded by the VS.NET2003 linker
- Next by Date: Re: static variables discarded by the VS.NET2003 linker
- Previous by thread: static variables discarded by the VS.NET2003 linker
- Next by thread: Re: static variables discarded by the VS.NET2003 linker
- Index(es):
Relevant Pages
|