It is currently Mon, 04 Mar 2024 02:54:29 GMT

Author Message
 initialize the global variables in .so files
I am facing one problem related to global variables in .so file. When
ever I access the variable the application is crashing

I have a class called services.
class  services
services(){ }
        void Add()  {  }
        void Delete(){ }

In another file I declared my global variable like this
services  gserviceObj;

Now I used this global variable 'gserviceObj' to access the member
function 'Add()',

gserviceObj.Add(); I am calling this Add() method of gserviceObj in
another file where the gserviceObj is declared as extern.

The application is crashing at gserviceObj.Add();. The constructor of
services is also not called till that point.

These all the files are in one .so. If I move the 'services
gserviceObj;' declaration to main and change the all the other
declarations in library(.so) to extern my application is working fine.

I am using gcc in Solaris environment.

Is there is any way to initialize the global variables in .so files
other than declaring it in main.
Can anybody help me in this?


 Tue, 24 Jun 2008 12:06:52 GMT   
 initialize the global variables in .so files

Two possibilities.
One is that the gservices.Add() is called before gservices is initialized
(e.g. the same shared library has a different global object
which initialization routine calls gservices.Add()).
The other is that the shared object is not built correctly.
I vaguely remember some version of g++ had to use g++
for linking step to make initializers correctly.
#pragma ident "Seongbae Park, compiler,"

 Tue, 24 Jun 2008 13:44:23 GMT   
   [ 2 post ] 

Similar Threads

1. initializing a global variable at apache startup

2. file contents into variable, or global variable from shell script

3. How do I read a ini file to initialize variables

4. how to initialize a global instance

5. Initializing ksh variables

6. Initializing variables

7. initializing a variable and simultaneously keeping terminal output

8. How to initialize complex per-cpu variables?

9. New to Linux: how are dev variables initialized?

10. EXPORTING global variables...

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