Re: static initializers do not get run in dylibs with gcc 3.3
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com On Dec 6, 2004, at 8:47 AM, Jan Hardenbergh wrote: 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. Any ideas? YON - Jan C. Hardenbergh _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/paulf%40aphrodite.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... The reason the static initializer works only when you call the no-op function is initializers are only run in a module when any symbols from that module are referenced. I think the theory (and I'm quoting my theory of the design rational, not my opinion) is there is no reason to run any static initializers in a module until anything from that module is referenced. Even without the hackMyClass() call, if you were to reference anything to do with MyClass, your static initializer will be run the first time you do. 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() 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. This email sent to paulf@aphrodite.com This email sent to site_archiver@lists.apple.com
participants (1)
-
Paul Forgey