http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54791
--- Comment #15 from Adi <adivilceanu at yahoo dot com> 2012-11-06 21:49:47 UTC --- This is a follow up on comment 14. It seems that -fPIC dramatically improved the way constructors are called. It seems that the linker has some logic and is initializing the globals from various object files in a correct order.(it somehow checks the dependencies betweeen globals I assume). I don't know how this is happening yet. As I see the ctors array has the same elements(except for the generated name that has changed), so something other then the ctors list is involved here. Do you know what? Now this works on my exe that is linked with static libs. Now if I go and link my exe with the shared version of my libs than it is not working. I saw this is because first all the constructors from the exe are called first and only after that constructors from the shared libs are called. But as I said I need some objects from the shared lib constructed first before objects in the main exe are initialized. Do you know how I can solve this case ?