I have a .cpp
file (let's call it statinit.cpp
) compiled and linked into my executable using gcc
.
My main()
function is not in statinit.cpp
.
statinit.cpp
has some static initializations that I need running.
However, I never explicitly reference anything from statinit.cpp
in my main()
, or in anything referenced by it.
What happens (I suppose) is that the linked object created from statinit.cpp
is never loaded on runtime, so my static initializations are never run, causing a problem elsewhere in the code (that was very difficult to debug, but I traced it eventually).
Is there a standard library function, linker option, compiler option, or something that can let me force that object to load on runtime without referencing one of its elements?
What I thought to do is to define a dummy function in statinit.cpp, declare it in a header file that main()
sees, and call that dummy function from main()
. However, this is a very ugly solution and I'd very much like to avoid making changes in statinit.cpp itself.
Thanks, Daniel