I have it:
a.cpp
int localfunction () { return 1; } int local_symbol = localfunction();
b.cpp
void thirdfunction () {};
main.cpp
void main () { thirdfunction (); }
When I compile this into the main executable, everything works (even with optimization), and the local function is executed at startup, even if I do not call it directly.
Now, in Visual C ++ and GCC, I put a.cpp and b.cpp in a static library (.lib). the local function is no longer executed / defined.
From what I understand, the character is recognized as "not in use" and it is deleted. But that sounds weird because:
- Why is it not deleted when I do not use the .lib file?
- Since lib is bundled, why does the linker reset initialization code?
What I'm trying to do is have a set of startup functions in every .lib file that I use to automatically log some data. The main executable should not know which files are linked or explicitly refer to the "local function" (/ INCLUDE works, but this is not optimal)
BTW: using various VC ++ options (OPT: NOREF, etc.) does not solve the problem.
Thanks! QbProg
source share