Re: Initilizing static C++ class variable problem
site_archiver@lists.apple.com Delivered-To: Darwin-dev@lists.apple.com On Mon, 31 Jan 2005, [ISO-8859-1] St?phane Letz wrote:
I'm using an Objective C framework that implement some initializing code in its "load" method. This initializing code indirectly access another C++ framework that uses static C++ class variables. It appears that the static C++ class variables are not initialized properly.
I read in the following page that says "load " is executed before main : http://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/gcc/ objective-c.html
Does it means that the load method must not access external framework? And that they are some restrictions in the kind of code that can be called in the load method ?
Good luck. C++ doesn't make any guarantees about _order_ of static initialization beyond guaranteeing that if the static variables/classes are in the "execution unit" (ie, .o file) they will be initialized in sequence. The way the OpenOffice.org project got around this was to use the "single module" linker option to link all source files into a single execution unit. Apple's dynamic linker (at run-time) has historically been quite bad at anything related to static data and C++, we've even filed some bugs and called in a TSI for it, but there are fundamental problems with the linker that are hard to fix. That said, I don't know if improvements have been made in that area for Tiger. Your best bet may be to use the single-module linker option, but you're kind of playing with fire when you're trying to rely on the dynamic linker to enforce the order of static initialization _across_ library boundaries. And don't take anything but Apple's documentation on gcc/dyld as authoritative, since the Apple toolchain is substantially different than the normal GNU toolchain (that's in RHEL for example), especially when it comes to run-time linking and object-file loading. Dan _______________________________________________ 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... This email sent to site_archiver@lists.apple.com
participants (1)
-
Dan Williams