From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29908 invoked by alias); 18 Mar 2010 11:40:17 -0000 Received: (qmail 29899 invoked by uid 22791); 18 Mar 2010 11:40:17 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from exprod6og108.obsmtp.com (HELO exprod6og108.obsmtp.com) (64.18.1.21) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 18 Mar 2010 11:40:05 +0000 Received: from source ([192.150.8.22]) by exprod6ob108.postini.com ([64.18.5.12]) with SMTP ID DSNKS6IREvvqvvEQ7joQ/5uVzITvZiXdViNC@postini.com; Thu, 18 Mar 2010 04:40:05 PDT Received: from inner-relay-1.corp.adobe.com ([153.32.1.51]) by outbound-smtp-2.corp.adobe.com (8.12.10/8.12.10) with ESMTP id o2IBdxs5005727; Thu, 18 Mar 2010 04:40:00 -0700 (PDT) Received: from nacas01.corp.adobe.com (nacas01.corp.adobe.com [10.8.189.99]) by inner-relay-1.corp.adobe.com (8.12.10/8.12.10) with ESMTP id o2IBdvTL021333; Thu, 18 Mar 2010 04:39:58 -0700 (PDT) Received: from nambxv01a.corp.adobe.com ([10.8.189.95]) by nacas01.corp.adobe.com ([10.8.189.99]) with mapi; Thu, 18 Mar 2010 04:39:57 -0700 From: "John (Eljay) Love-Jensen" To: Erik Rull CC: GCC-help Date: Thu, 18 Mar 2010 12:45:00 -0000 Subject: RE: Transitive Linking fails Message-ID: <4B7A6CC9992C4E4FB188D02872C90A6B134F57@nambxv01a.corp.adobe.com> References: ,<4BA16A4F.2010507@rdsoftware.de> In-Reply-To: <4BA16A4F.2010507@rdsoftware.de> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: 2010-03/txt/msg00228.txt.bz2 Hi Erik, > Well, the linking itself was now fine, but I've got new problems in parts= of the software that do not use parts of the library. That sounds odd and unexpected to me. > When I link the .o files directly into the shared object, then I have no = problem, the software runs fine then. > I've built the lib using > $(AR) rcs libx.a obj1.o obj2.o > where $(AR) put out "ar" That looks good. > As far as I understood it these two commands should result in the same fi= le: > $(LD) (shared object options) libshared.so libx.a obj5.o obj6.o > and > $(LD) (shared object options) libshared.so obj1.o obj2.o obj5.o obj6.o > right or not? No, not right. For the libx.a file, the linker will only pull over the items from the libx= .a that are associated with unresolved symbols. Since the files are processed in order (left-to-right), as specified on the= command-line, the libx.a is processed first. When the libx.a is processed, at that time there are no unresolved symbols,= so nothing will be copied out of the libx.a archive. > If not what must be done to make these two lines behaviour equivalent? Try this: $(LD) (shared object options) libshared.so obj5.o obj6.o libx.a However... If you really, really, really want everything included from the libx.a into= libshared.so: $(LD) (shared object options) libshared.so obj5.o obj6.o --whole-archive li= bx.a --no-whole-archive However, I discourage that approach. Instead I suggest you extract out all= the .o files from the libx.a, and put them on the link line explicitly: $(AR) x libx.a obj1.o obj2.o $(LD) (shared object options) libshared.so obj5.o obj6.o obj1.o obj2.o > or must I take -static -lx? Even if you use -static -lx, the order is still important and must appear a= fter your object files (*.o). Also, you need to "undo" the static state after your library parameters, ot= herwise the static state is still in effect for any implicit libraries. (I= n such a situation people might say, "Why does my libshared.so go from 17 K= B to 200 MB with the -Bstatic directive?") $(LD) (shared object options) libshared.so obj5.o obj6.o -Bstatic -lx -Bdyn= amic Sincerely, --Eljay