From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4496 invoked by alias); 24 Aug 2012 09:40:02 -0000 Received: (qmail 4476 invoked by uid 22791); 24 Aug 2012 09:40:01 -0000 X-SWARE-Spam-Status: No, hits=-5.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-iy0-f175.google.com (HELO mail-iy0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 24 Aug 2012 09:39:48 +0000 Received: by iaky10 with SMTP id y10so3148325iak.20 for ; Fri, 24 Aug 2012 02:39:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.191.165 with SMTP id gz5mr1434934igc.50.1345801187997; Fri, 24 Aug 2012 02:39:47 -0700 (PDT) Received: by 10.42.49.81 with HTTP; Fri, 24 Aug 2012 02:39:47 -0700 (PDT) In-Reply-To: References: Date: Fri, 24 Aug 2012 13:40:00 -0000 Message-ID: Subject: Re: libstdc++ From: Jonathan Wakely To: naga raj Cc: gcc-help Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2012-08/txt/msg00224.txt.bz2 On 24 August 2012 08:46, naga raj wrote: > Hi, > > I have ported Gcc-4.6.2 to an embedded target. My C++ compiler is > generating huge code size. > > #include > using namespace std; > int main() > { > return 0; > } > > If we execute the above program then all the function in the > iostream library are included in the elf as a result size of elf is > increased.... Including causes global objects to be constructed, so even though you're not explicitly using std::cout or std::cin, those streams are initialized and code is run (before main) just because is included. If you don't need to use it then don't include it. If you do need to use it then obviously the code size is larger if you use I/O features than if you don't use them. That said, libstdc++ isn't really optimised for embedded systems. Some configure-time options such as building libstdc++ without exceptions can help reduce code size, if you don't need to use exceptions. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43852 would also help avoid dependency on the I/O facilities.