<div class="gmail_quote">On 15 April 2012 07:09, Walter Bright <span dir="ltr"><<a href="mailto:newshound2@digitalmars.com">newshound2@digitalmars.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I just tried it, and I got the error I expected:<br>
<br>
LIBCMTD.lib(atox.obj) : error LNK2005: _atoi already defined in Unit.obj<br>
<br>
In C, I would always explicitly declare weak linkage to do this... what's the<br>
point of the weak attribute if not for this?<br>
</blockquote>
<br></div>
First you need to find out why you have multiple definitions of the same symbol being linked together. For example, do not specify libcmtd.lib to the linker, then link, then see what your unresolved symbols are.<br>
</blockquote></div><br><div>I have multiple definitions because I defined a function from the lib in one of my own objects, and then they get linked together.</div><div>If I were to not specify libcmtd, every CRT call would be unresolved, except atoi in this case which I implemented in one of my objects. The point is, if I implement a function from a library, I get the behaviour I expect, which is the linker complains about multiply defined symbols. Your saying though, that I should be able to implement a library function in my own code, and that will somehow be found prior to searching the libs, and since the symbol is resolved, the lib search will not take place.</div>
<div>How is the linker supposed to know which instance (my one in a loose .o file, or the one in the lib) is actually 'my' one? What if it was contained in 2 different libs, rather than one in a lib, and the other in a bundle of loose object files?</div>
<div><br></div><div>When and how can I expect the behaviour you propose? I don't follow the requirements... or the logic the linker could follow. At link time, it no longer know's what's mine from what's in any given libs...</div>
<div>As far as I was aware, I thought it DID just link every single thing given together in one huge blob, and then strips the unreferenced stuff as a post process.</div>