When you define the same function (non-static) in two different C source files, compile them and link them with the Microsoft linker, you get a duplicate symbol error message, as expected.
On the other hand, when you define a function that matches the name of a standard library function e.g. cos
(which is not defined as COMDAT) then there is no error; your definition silently overrides the standard library definition. This is also the desired behavior, but I'm trying to figure out what the exact rule is.
Is the rule 'symbols defined in an object file override symbols defined in a library file' or something else? I can't find any mention of this in the PE specification, but maybe I'm overlooking something.
The MS linker links only those member objects from static libraries that are needed to resolve dependencies. Unused member objects from static libraries are optimized away. Therefore if you have a duplicate symbol in a static library member object, but the member object is not needed, no error will arise. See also: http://msdn.microsoft.com/en-us/library/72zdcz6f.aspx
It seems like the MS linker also supports some kind of weak symbols: http://support.microsoft.com/kb/148652/EN-US http://nikoniko-programming.blogspot.ch/2010/09/aliasing-symbol-names-during-link-time.html
But I can't find this in the MSDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With