This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Initialization methods in library..
- From: "Ajay Bansal" <abansal at netegrity dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Tue, 26 Aug 2003 10:33:16 +0530
- Subject: Initialization methods in library..
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.