Re: static variables discarded by the VS.NET2003 linker

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



You have two solutions, both in linker options

a) Linker/Optimization/References, turn off "eliliminate unreferenced data"
or
b) Linker/Input/Force Symbol Reference, add your global vars there

<bdachev@xxxxxxxxx> wrote in message
news:1172139754.837798.197130@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi Everyone,

I found a thread on that topic posted year 2004 but not satisfied with
the information there. So I decided to raise that issue once again.

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.

I am not sure what should be the correct behaviour of the linker in
that case but could anyone let me know how to overcome that problem
and make the linker to include the needed object files without forcing
it to include any object files from given library even if not
referenced at all?

Can we say that in my case objects are not referenced at all since
even if they are not referenced directly still it is possible to be
reference via the container object?

Many thanks in advance!
Best regards,
Boris.



.



Relevant Pages

  • static variables discarded by the VS.NET2003 linker
    ... an object file containing definitions of global variables of any type/ ... would be accessed via that global container. ... and make the linker to include the needed object files without forcing ... reference via the container object? ...
    (microsoft.public.vc.language)
  • How a linker works (continued)
    ... Some people insisted that I was generalizing too much and there could be C implementations without object files and C implementations that do not link files in separate compilation but just parse and digest each module, making the whole code generation step in the linker, from an unknown representation. ... Here I am speaking about the very common where the compiler produces traditional object files, ... and two types of relocations for the debug information, ...
    (comp.lang.c)
  • Re: system constants in COBOL
    ... and never get to the linker. ... What is worse the extra code will be a memory reference. ... 01 RETURN-STATUS PIC S9COMP. ... STL R17, -8 ...
    (comp.os.vms)
  • Re: system constants in COBOL
    ... and never get to the linker. ... What is worse the extra code will be a memory reference. ... 01 RETURN-STATUS PIC S9COMP. ... STL R17, -8 ...
    (comp.os.vms)
  • Re: extern variable
    ... the linker is from another GNU package ... GNU doc, ... actually invoked under) gcc marks items in the object files as ... AFAIK GNU ld always does this for common, ...
    (comp.lang.c)