From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7980 invoked by alias); 25 Jan 2005 17:11:13 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 7963 invoked from network); 25 Jan 2005 17:11:10 -0000 Received: from unknown (HELO wproxy.gmail.com) (64.233.184.202) by sourceware.org with SMTP; 25 Jan 2005 17:11:10 -0000 Received: by wproxy.gmail.com with SMTP id 63so45359wri for ; Tue, 25 Jan 2005 09:11:10 -0800 (PST) Received: by 10.54.20.25 with SMTP id 25mr284380wrt; Tue, 25 Jan 2005 09:11:09 -0800 (PST) Received: by 10.54.19.12 with HTTP; Tue, 25 Jan 2005 09:11:09 -0800 (PST) Message-ID: <36f656ba050125091170e2f2d0@mail.gmail.com> Date: Tue, 25 Jan 2005 17:11:00 -0000 From: Nick Steckler Reply-To: Nick Steckler To: gcc-help@gcc.gnu.org Subject: global objects not initializing -- GCC 3.2.3 Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SW-Source: 2005-01/txt/msg00224.txt.bz2 I'm looking for the reason why global objects defined in statically-linked libraries are not initialized at run time. Example: ------------------------------------------------------------------------------- bash@puma$ cat lib.cpp #include class X { public: X() { std::cout << "Inside X constructor\n"; } }; // instantiate global object X x; bash@puma$ cat make_static g++ -g -c -o lib.o lib.cpp ar -r libTest.a lib.o stecklen(bash)@puma[link_test]$ ./make_static stecklen(bash)@puma[link_test]$ cat main.cpp #include int main() { std::cout << "Inside main.\n"; return 0; } bash@puma$ cat make_bin g++ -g -I. main.cpp -L. -lTest -o main.out bash@puma$ ./make_bin bash@puma$ ./main.out Inside main. bash@puma$ ------------------------------------------------------------------------------- If I change the line that makes the lib to "g++ -shared -o libTest.so lib.o" and recompile main, the object is initialized. Why is this? Thanks for any information.