Initialization methods in library..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have an application that calls a init method in a library lib1 using the
following directive

static void __attribute__ ((__constructor__)) _initfunc();

where _initfunc() is a global method. This method internally calls a method
on a static member variable of a class as shown below

static void _initfunc()
{
      g_Master::CacheCount->Setvalue(1);
}

where the class g_Master is defined in the source file of a library lib2 as
follows

class g_Master
{
     public:
          static CSmSimpleObj CacheCount;
           ................................................
}

CSmSimpleObj g_Master::CacheCount;

The problem is that the initialization of the static member variable in lib2
does not happen before the SetValue method is invoked on it in lib1.
Consequently a core dump occurs. 

The application has been compiled using gcc 3.2.1 on Linux Advance Server
2.1. The above piece of code works fine on Solaris 5.8 if I use the
corresponding #pragma init directive to invoke the init method _initfunc().
Can someone please tell me how I can guarantee initialization of the static
class variables before they are being actually used.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux