From: Brooks Moses <bmoses@stanford.edu>
To: binutils@sources.redhat.com
Subject: Using "weak externals" with ld on cygwin?
Date: Wed, 12 Apr 2006 08:40:00 -0000 [thread overview]
Message-ID: <443C9F66.8000106@stanford.edu> (raw)
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
next reply other threads:[~2006-04-12 6:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-12 8:40 Brooks Moses [this message]
2006-04-17 6:19 Danny Smith
2006-04-17 12:52 ` Brooks Moses
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=443C9F66.8000106@stanford.edu \
--to=bmoses@stanford.edu \
--cc=binutils@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).