This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: global objects not initializing -- GCC 3.2.3


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]