global objects not initializing -- GCC 3.2.3
Eljay Love-Jensen
eljay@adobe.com
Tue Jan 25 17:49:00 GMT 2005
Hi Nick,
>I'm looking for the reason why global objects defined in
statically-linked libraries are not initialized at run time.
Your global object named x is not used in main.cpp, so it is not being
included (sort of like the opposite "dead code stripping" -- "live code
inclusion"). And hence, is not being constructed.
To force all the symbols (and their corresponding objects) to be
incorporated into your main.out from your archive regardless of use, change
your compilation like this:
g++ -g -I. main.cpp -L. -Wl,--whole-archive -lTest -Wl,--no-whole-archive
-o main.out
HTH,
--Eljay
More information about the Gcc-help
mailing list