From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16660 invoked by alias); 20 Dec 2011 05:38:25 -0000 Received: (qmail 16479 invoked by uid 22791); 20 Dec 2011 05:38:23 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-gy0-f175.google.com (HELO mail-gy0-f175.google.com) (209.85.160.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 20 Dec 2011 05:38:10 +0000 Received: by ghrr17 with SMTP id r17so2291062ghr.20 for ; Mon, 19 Dec 2011 21:38:10 -0800 (PST) Received: by 10.236.174.3 with SMTP id w3mr706509yhl.117.1324359490277; Mon, 19 Dec 2011 21:38:10 -0800 (PST) Received: by 10.236.174.3 with SMTP id w3mr706493yhl.117.1324359490172; Mon, 19 Dec 2011 21:38:10 -0800 (PST) Received: from coign.google.com ([216.239.45.130]) by mx.google.com with ESMTPS id u47sm1280742yhl.0.2011.12.19.21.38.08 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Dec 2011 21:38:09 -0800 (PST) From: Ian Lance Taylor To: Anthony Weston Cc: gcc-help@gcc.gnu.org Subject: Re: Statically linking in a static library References: Date: Tue, 20 Dec 2011 05:38:00 -0000 In-Reply-To: (Anthony Weston's message of "Mon, 19 Dec 2011 16:21:02 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: 2011-12/txt/msg00145.txt.bz2 Anthony Weston writes: > I'm having trouble with statically linking. I've created a static > library that statically links to other static libraries. My hope by > doing this was so other users would only need to include one static > library when linking in their executable. However when I nm the > created the static library all the references are unresolved. Is > there an argument that will force the linker to resolve these symbols? > > Example: > > libA.a defines functionA. > libB.a defines functionB. > > I create libC.a which statically links and uses both libA.a and libB.a. > > When running nm libC.a the results show that neither functionA nor > functionB can be resolved so libA.a and libB.a also need to be > statically linked into the final executable. Yes, that is how Unix linkers work. If you want the final program to be able to only link against a single library, then you will need to incorporate libA.a and libB.a into libC.a. E.g., do something along the lines of ar x libA.a ar x libB.a ar rc libC.a *.o Ian