It is currently Sat, 04 Feb 2023 11:48:44 GMT



 
Author Message
 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?



 Tue, 19 Apr 2005 05:29:19 GMT   
 Shared libraries and global variables

Use pointers?



 Tue, 19 Apr 2005 13:00:02 GMT   
 Shared libraries and global variables

It appears to be a bug in gdb!  If I single-step through the code, it
functions correctly.  I'm using gdb 5.1.90CVS-5 on Red Hat 7.3.



 Tue, 19 Apr 2005 23:39:48 GMT   
 
   [ 3 post ] 

Similar Threads

1. Singleton global variable in a shared library

2. global variable with shared library

3. Global variables inside shared library on Solaris

4. Visibility of global variables in shared libraries

5. global variable in shared library?

6. global variable in shared library.

7. Problems with shared libraries and external global variables

8. Global data sharing in shared libraries

9. Shared variable between main() and loaded shared library - dlopen()

10. shared variables in shared libraries


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software