From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hendrik Visage Subject: Re: Does GCC link only used functions? Date: Thu, 2 Feb 2006 07:17:31 +0200 Message-ID: References: <200601291438.17093.samjnaa@gmail.com> <17373.1722.484465.747500@cerise.gclements.plus.com> Mime-Version: 1.0 Content-Transfer-Encoding: 7BIT Return-path: In-Reply-To: <17373.1722.484465.747500@cerise.gclements.plus.com> Content-Disposition: inline Sender: linux-c-programming-owner@vger.kernel.org List-Id: Content-Type: text/plain; charset="us-ascii" To: Glynn Clements Cc: Shriramana Sharma , Linux C Programming List On 1/29/06, Glynn Clements wrote: > > Shriramana Sharma wrote: > > So does this mean that GCC links only those functions from a library which I > > call directly or indirectly through another called function in the course of > > my program? > For a static library (which is just an archive of object files), the > linker will only use those object files which are necessary to satisfy > any outstanding references. That means that all the functions and everything in that object file is included? thus given the lib.a contains obj1.o and obj2.o compiled from obj1.c & obj2.c below, the program main from main.c below, linked with lib.a will contain the obj1.o part, which will also include the superflouos int b() (That's the way I understood it too), but not obj2 with c() & d(). that's the reason why static libraries makes use of small objects to minimize the stuff linked in. obj1.c: int a(){return 1;} int b(){return 2;} obj2.c int c(){return 3;} int d(){return 4;} main.c int main(){ return a(); } -- Hendrik Visage