From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11237 invoked by alias); 18 Jul 2006 09:44:18 -0000 Received: (qmail 11228 invoked by uid 22791); 18 Jul 2006 09:44:18 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 18 Jul 2006 09:44:16 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k6I9iDNV016349; Tue, 18 Jul 2006 05:44:13 -0400 Received: from pobox.surrey.redhat.com (pobox.surrey.redhat.com [172.16.10.17]) by int-mx1.corp.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k6I9iCqF027205; Tue, 18 Jul 2006 05:44:12 -0400 Received: from [10.32.68.7] (vpn-68-7.surrey.redhat.com [10.32.68.7]) by pobox.surrey.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k6I9iBCB014467; Tue, 18 Jul 2006 10:44:12 +0100 Message-ID: <44BCAD6A.7020507@redhat.com> Date: Tue, 18 Jul 2006 09:44:00 -0000 From: Nick Clifton User-Agent: Thunderbird 1.5.0.4 (X11/20060516) MIME-Version: 1.0 To: "Browder, Tom" CC: binutils@sourceware.org Subject: Re: Static Linking and Library Dependencies References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2006-07/txt/msg00222.txt.bz2 Hi Tom, > Say I have two static libraries A and B. > In A there is only one function, foo, that depends upon B. > My program uses functions in A other than foo. > Is there any way to link my program with A but not have to link B also? Yes. I am tempted to just leave the answer there, but I will be nice. If the other functions in A which are used by your program are in different object files within the library then B will not be linked it at all, and you will not have to do any extra work. If there are functions in A which are used by your program and which are in the same file(*) as foo then you have two choices. If you have access to the sources for A then you can recompile it with the -ffunction-sections switch and then link with the --gc-sections switch. This should allow foo and its dependencies in B to be discarded by the linker. (Alternatively you can hand edit the sources for A so that foo is compiled in its own file). If you do not have the sources for A then you can create a dummy version of the B library that is empty apart from the symbols needed to satisfy the references in foo(). Then you can use this dummy library in place of B. This solution is not as elegant but it should work. Cheers Nick (*) Strictly speaking I should be talking about "compilation units" here rather than "files".