Reputation:
If I am using a function that has the following signature:
void foo(int i);
And this function exists in libxxx.lib and also in libyyy.lib (but the implementation for the function is different in each lib file), so what happens if I link my object file against these two lib files? Will I get an error that the function exists in both lib files or will the linker choose a random function or something else?
Upvotes: 3
Views: 1571
Reputation: 149095
Normally a linker should only get unresolved symbols from a static library. So if the function void foo(int i)
is called from one of the object files given to the linker, it will use the version present in first library given in the command line. Because once the symbol has been found in first library, it is no longer unresolved when looking at second one.
It would be different if same symbol was defined in two object files, because it would lead to a linker error.
And the problem is hard to solve if the function void foo(int i)
is called from another static library, because now it depends on the relative order of the 3 libraries. My advice is that if you can, you should avoid that corner case.
Upvotes: 4