0

I have recently decided to upgrade to using shared libraries (home-brewed) instead of static libraries to support one of my group's projects. This way, my group can take advantage of in-place updates to the library as opposed to full recompiles of the main project (which must currently be done for the static libraries).

My library code has global variables that change as the main program interacts with the library. This works just fine when the library is static, but I am worried about transitioning to it being a shared library. If two programs use the same shared library, will they conflict with each other due to the global variables in the shared library?

Important note: The shared library is loaded when the program starts. I do NOT yet plan to have the library loaded dynamically (through dll commands). I am using gcc for compiles for an ARM-based system running Linux.

Mike Foss
  • 311
  • 2
  • 6
  • What do you mean with conflict? You mean that both read and write the same global variables? – katzenversteher Apr 12 '12 at 18:47
  • Possibly useful: http://stackoverflow.com/a/1780531/98654 – Nate Kohl Apr 12 '12 at 18:49
  • Also: http://stackoverflow.com/questions/1979303/is-global-variable-in-a-shared-library-dll-shared-across-process – Nate Kohl Apr 12 '12 at 18:50
  • By 'conflict', I mean exactly that--the global variable may be modified (written to, read from), potentially in different processes. – Mike Foss Apr 12 '12 at 19:04
  • Thanks, Nate, for the links! The second one pretty much answers my question: "Linux does not support sharing of global variables that are laid out by the linker." If I understand this correctly, then separate programs that use the same shared library (linked to when the program starts) will each have its own set of global variables used in the shared library. I guess I wasn't putting in the right search terms when looking for the answer... – Mike Foss Apr 12 '12 at 19:11
  • 2
    Shared libraries only share code, not data. – n. m. could be an AI Apr 12 '12 at 19:24
  • Though even with a static library, you should not need to recompile the main project. Just relinking is required. – nos Apr 12 '12 at 19:37

0 Answers0