As far as my practical tests go, when linking a static library (.lib
) into your executable in Visual-C++, if any executable .obj file defines a duplicate symbol to one in the static library, the symbol in the static library will be silently ignored.
Confirm ( Feb 18 '10 at 17:46 Michael Burr):
MSVC used to behave such that if a symbol is defined in a .obj file and a .lib it would use the one on the .obj file without warning. I recall that it would also handle the situation where the symbol is defined in multiple libs it would use the one in the library named first in the list.
I can't say I've tried this in a while, but I'd be surprised if they changed this behavior (especially that .obj defined symbols override symbols in .lib files).
A brief test with VS 2010 RC indicates that the behavior I described is still there.
('Windows Static Library with Default Functions' seems also a confirmation to me)
Now first of all, I would love to be proven wrong, but at least for a regular C++ function this seems to be the way it is.
Second, is there any way to prevent this? I have a function, that when any binary links to the static library containing this function, I would like to confirm that the version from the static library is actually used, and not some leftover or whatever in the other project. (Do note: Fn in question is test_suite* init_unit_test_suite(int argc, char* argv[])
, (*) so I cannot practically change it because it is from a third party lib.)
(*): This is the Boost.Test main function that should be supplied by a custom static lib of ours. If any dev creates a Unit Test project -- which are linked to the static lib automatically through a property sheet -- but erroneously also defines the function, the build should break instead of using the dev supplied function.