
Shared libraries and global variables
I have a shared library that has a global variable and a funtion that
references that variable:
shared.c:
int g_var = 0;
void f1(void)
{
if (g_var)
// do something
Then I have an executable that links in the shared library, and
updates the global variable:
main.c:
extern int g_var;
int main(void)
{
g_var = 1;
fl();
When I'm inside main(), my de{*filter*} (gdb) tells me that g_var is
indeed equal to 1 before the call to fl(). &g_var contains
0x81823820. When I'm inside fl(), however, gdb tells me that g_var is
0! When I ask gdb to display &g_var, it gives me 0x450340F0! Why are
there two different versions of g_var!?!?!? And how do I fix this?