Calling constructor functions manually
Ian Lance Taylor
iant@google.com
Thu Oct 14 20:43:00 GMT 2010
"Michał Bieliński" <michal@kast.net.pl> writes:
> I am linking C object files which rely on functions with constructor
> attribute with my program. Ordinarily gcc generates code calling all such
> routines before main gets control. However, my program is not written in C
> and such code is not included. Resulting executable works but linked
> objects refuse to cooperate because their initializing constructors were
> not called. Is there a way to manually run these functions?
In general, yes. However, the precise details depend greatly on your
target. So tell us more.
In general you will want to link crtbegin.o before all your .o files and
crtend.o after them. Then generally the .init section should contain
what you need.
Ian
More information about the Gcc-help
mailing list