This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Using "weak externals" with ld on cygwin?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]