[Bug target/54791] AIX-only: Constructors are not called in main program.
dje at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Nov 6 14:46:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54791
--- Comment #13 from David Edelsohn <dje at gcc dot gnu.org> 2012-11-06 14:46:34 UTC ---
> Because if you have a function declared as inline in a header file that gets
propagated to multiple source files is ok, but in my case that inline keyword
was removed by some $ifdef LINUX and so I end up with having the constructor
body defined in the header like this: ClassA::ClassA(){//body}. Now because
this is in the header it will propagate to all sources that includes it. So
finally I end up with that constructor in multiple constructors sources. This
would not happen if the inline keyword have not been removed from it. This was
a bug in our code and I removed it.
Okay, so the problem was *lack* of inlined constructors. Now that makes more
sense.
> Our project has one exe and several shared and static libs. To make the
things easier I moved every source file in the exe. Now the problem I have is
with the order of the initialization of global objects that reside in multiple
object files. I need objects in a source file by constructed first before any
other objects in the rest of the files are constructed.
If you actually create shared libraries, you should add -fPIC to the
compilation command. This also adds some additional uniqueness to symbols.
> You said that I can decorate the constructors with a priority. How to do that
? Before migrating from xlC we used #pragma priority. This is ignored by gcc.
We also used -qpriority flag of xlC. Also gcc does not have something like
this. Or?
Use __attribute__ ((init_priority (NNNN)))
http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
More information about the Gcc-bugs
mailing list