How does a dynamic library’s references to a global variable get translated once in the running app

cdynamic-linking

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?

Best Answer

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.

Related Topic