static library in two modules
-
I have one static library named c.lib, in which there is a global member int gC; Two other modules, a.exe and b.dll(regular dll using mfc), link to c.lib. I found that the address of gC is different in a.exe between in b.dll. Is it strange? How can I make only one global int gC?(but used both in c.lib, b.dll, and a.exe)
-
I have one static library named c.lib, in which there is a global member int gC; Two other modules, a.exe and b.dll(regular dll using mfc), link to c.lib. I found that the address of gC is different in a.exe between in b.dll. Is it strange? How can I make only one global int gC?(but used both in c.lib, b.dll, and a.exe)
How you are refering or Declaring the variable gC for a.exe and c.lib ?
-
I have one static library named c.lib, in which there is a global member int gC; Two other modules, a.exe and b.dll(regular dll using mfc), link to c.lib. I found that the address of gC is different in a.exe between in b.dll. Is it strange? How can I make only one global int gC?(but used both in c.lib, b.dll, and a.exe)
code_discuss wrote:
found that the address of gC is different in a.exe between in b.dll. Is it strange?
No, because the individual modules get their own personal instance of the variable. Two of the possible solutions are 1) Put the common static library code in a DLL instead. 2) Use conditional compilation to only create the variable in on module (i.e. in the DLL module only) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
How you are refering or Declaring the variable gC for a.exe and c.lib ?
I define int gC in a cpp file in the static library project. In b.dll and a.exe, when I want to use gC, I use
extern int gC
;