Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. static library in two modules

static library in two modules

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    code_discuss
    wrote on last edited by
    #1

    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)

    R M 2 Replies Last reply
    0
    • C code_discuss

      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)

      R Offline
      R Offline
      Rajkumar R
      wrote on last edited by
      #2

      How you are refering or Declaring the variable gC for a.exe and c.lib ?

      C 1 Reply Last reply
      0
      • C code_discuss

        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)

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        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:

        1 Reply Last reply
        0
        • R Rajkumar R

          How you are refering or Declaring the variable gC for a.exe and c.lib ?

          C Offline
          C Offline
          code_discuss
          wrote on last edited by
          #4

          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;

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups