Re: static variables discarded by the VS.NET2003 linker

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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

.



Relevant Pages

  • Re: Im a stupid blond :( Please help me!!!
    ... > in a program to be left out of the external references table. ... Well for one the linker that comes with Microsoft Visual Studio 6 (not ... It's the loader's job to adjust ... > get the entire object file that contains that function linked in. ...
    (comp.lang.cpp)
  • Re: Questions about linking.
    ... My other question is about static linking. ... In other words, does the linker select the necessary stuff, not the ... If so,is it applied to the LIB's global variables which are accessed by ...
    (comp.os.minix)
  • Re: Singleton/global question in 64 vs 32 bits
    ... You shouldn't link the static library with the DSO. ... executable with the static library and leave the references in the DSO ... The runtime linker will resolve the static library entry ... to link the object file with the executable. ...
    (comp.unix.programmer)
  • Re: Im a stupid blond :( Please help me!!!
    ... >> in a program to be left out of the external references table. ... >> object file that contains the code for that referenced function. ... > That doesn't happen with all linkers ... I am very interested in exploring this and that information ...
    (comp.lang.cpp)
  • Re: Unblessed reference.
    ... are returning references to references. ... in a variable of the worksheet object. ... sub create_excel_file { ... If you have groups of global variables specific to each other, ...
    (comp.lang.perl.misc)