If a dynamic library exports the address to a global variable defined within the library, how are accesses to that variable translated during dynamic linking so that a running application can interact with it?

  • Compiling does the same thing as always - it dumps its symbol table into the object code, translating variable names into offsets. Fixing up the address so that an already running process can read/write it is the job of the dynamic linker or loader. Jun 5, 2013 at 12:10
  • Do you mean a global variable? In C, which you tagged your question with, static variables have internal linkage - they're not visible outside the translation unit, much less outside a dynamic library. Jun 5, 2013 at 12:40
  • @KilianFoth true. I will edit my question.
    – Victor
    Jun 5, 2013 at 13:25
  • @SebastianRedl yes, I did mean to say global, thank you.
    – Victor
    Jun 5, 2013 at 13:26
  • Do you really mean: "If a dynamic library exports the address of a global variable defined within the library"? That changes the meaning of the question! Jan 3, 2019 at 17:38

1 Answer 1


Dynamic linking is operating system specific (and very different on Linux and on Windows; read Levine's Linkers and Loaders book).

For Linux, a good explanation happens in Drepper's How to write shared libraries paper.

In general, the access to such a global variable may involve some indirection. Read about the Global Offset Table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.