RE: static initializers do not get run in dylibs with gcc 3.3
RE: static initializers do not get run in dylibs with gcc 3.3
- Subject: RE: static initializers do not get run in dylibs with gcc 3.3
- From: "Jan Hardenbergh" <email@hidden>
- Date: Tue, 7 Dec 2004 08:59:56 -0500
- Thread-topic: static initializers do not get run in dylibs with gcc 3.3
That's a good idea, but, that is not what is happening.
This is a dylib that is registering procedure pointers to be called externally, so, understanding who is calliing them is hard.
But, no matter what optimization level I use (-g, -O0, -O2) the code is there. If I call hackMyClass(), then magically, the constructor for myClass is run. So, the code is there.
The optimization levels do make a difference. The dylib has about 25 classes in it. With -O2, no static initializers run. With -O0 and -g, 9 of the static initializers run.
So, currently, I compile -O0 and call 16 hackMyClass() routines and it works.
I'd like to get rid of those 16 calls. It seems like many people have run into this problem and there seem to be many piecewise solutions.
YON - Jan C. Hardenbergh, email@hidden, 978-369-6500x272
Director of VolumePro Software Engineering, TeraRecon, Inc. Concord Office
-----Original Message-----
From: Jerry Pendergraft [mailto:email@hidden]
Sent: Monday, December 06, 2004 4:21 PM
To: Jan Hardenbergh
Cc: email@hidden
Subject: Re: static initializers do not get run in dylibs with gcc 3.3
Perhaps this is way too simple, but in your example there is no reference
to myClass other than its declaration. Is it possibly the compiler
recognized that and "optimized" the code away?
--
Jerry Pendergraft email@hidden
Endocardial Solutions voice: 651-523-6935
1350 Energy Lane, Suite 110 fax: 651-644-7897
St Paul, MN 55108-5254 mobile: 651-491-0163
On Mon, 6 Dec 2004, Jan Hardenbergh wrote:
> I am having a problem with static initializers. This problem is well documented if you Google:
> "mac osx gcc static initializers" or variations. It works on about 1/4 of the classes. I cannot
> discern which ones it will or will not work with. The static is instantiated if I call hackMyClass()
>
> My flavor of the Problem is
>
> class MyClass {
> MyClass()
> {
> do some init
> }
> ...
> }
>
> static MyClass myClass;
>
> hackMyClass() { return; }
>
> This works on Linux with gcc 3.3, MSVC++, and Solaris.
>
> This was rumored to have been fixed with GCC 3.3, but, it is not for me. I have tried all fo the link flags that seemed to make any sense.
>
> Any ideas?
>
> YON - Jan C. Hardenbergh
>
>
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden