Hello there, I have this:
a.cpp
int localfunction () { return 1; }
int local_symbol = localfunction();
b.cpp
void thirdfunction () {};
main.cpp
void main () { thirdfunction (); }
When I compile this in a main executable everything works (even with optimizations), and the localfunction is executed at startup even if I don't call it directly.
Now, in Visual C++ and GCC , I put a.cpp and b.cpp in a static library (.lib). localfunction is no more executed/defined.
From what I understand the symbol is detected as "not used" and it is removed. But it sounds weird because:
- Why it is not removed when I don't use the .lib file?
- Since the lib is linked in, why the linker blows away the initialization code?
What I'm trying to do to is to have a set of startup function in every .lib file I use that register automatically some data. The main executable should not know what files are linked in nor explicitly reference "localfunction" (/INCLUDE does works but it is not optimal)
BTW : using the various VC++ options (OPT:NOREF , etc..) doesn't solve the problem.
Thank you! QbProg