From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27055 invoked by alias); 12 Apr 2006 06:40:13 -0000 Received: (qmail 27045 invoked by uid 22791); 12 Apr 2006 06:40:12 -0000 X-Spam-Check-By: sourceware.org Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 12 Apr 2006 06:40:07 +0000 Received: from root by ciao.gmane.org with local (Exim 4.43) id 1FTZ1F-0003ei-Rd for binutils@sources.redhat.com; Wed, 12 Apr 2006 08:40:01 +0200 Received: from dnab42a4b3.stanford.edu ([171.66.164.179]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 12 Apr 2006 08:40:01 +0200 Received: from bmoses by dnab42a4b3.stanford.edu with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 12 Apr 2006 08:40:01 +0200 To: binutils@sources.redhat.com From: Brooks Moses Subject: Using "weak externals" with ld on cygwin? Date: Wed, 12 Apr 2006 08:40:00 -0000 Message-ID: <443C9F66.8000106@stanford.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) 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-04/txt/msg00167.txt.bz2 I've been pounding my head all day against trying to use weak symbols in libraries on Cygwin, and have finally gotten to the point where I need to admit defeat and ask for help. In the online documentation for ld, version 2.16 [1], I find the following statement at the bottom of the page: "The Windows object format, PE, specifies a form of weak symbols called weak externals. When a weak symbol is linked and the symbol is not defined, the weak symbol becomes an alias for some other symbol." My understanding of this is that I should be able to create a libA.dll file with some code in it that references a function foo(), and define foo() as a weak symbol aliased to bar() such that, if an executable defines its own foo() or links to another dll that defines it, the libA code will use that definition of foo(), but otherwise it will use bar(). Is that actually a correct understanding? Or am I missing something somewhere? I've been trying, with a copy of the release version of gcc 4.1.0 and the latest Cygwin version of ld (which reports GNU ld version 2.16.91 20050610 as its version), to write some code that will do that. Everything I try seems to either give me an error like "Cannot export .weak.__Z3foov.__Z3barv: symbol not found" or else always uses bar() regardless of whether I supply a foo() elsewhere. I'm not sure I've got a very good idea at all how to do it correctly, though; the ld manual seems to provide no useful details beyond the above statement, and I haven't found much helpful in the gcc manual either. If this is possible on Cygwin, can anyone provide a simple but complete example of how to make it work? Ideally a C++ example, but I'll be happy with anything I can compile and run. :) Thanks muchly, - Brooks [1] http://sourceware.org/binutils/docs-2.16/ld/WIN32.html