This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: global objects not initializing -- GCC 3.2.3
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Nick Steckler <nicksteck at gmail dot com>, gcc-help at gcc dot gnu dot org
- Date: Tue, 25 Jan 2005 11:50:32 -0600
- Subject: Re: global objects not initializing -- GCC 3.2.3
- References: <36f656ba050125091170e2f2d0@mail.gmail.com>
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