views:

43

answers:

1

Hi,

Is it a problem if I have an executable and a library use different versions of another library.

Example:

If I have an executable: A.exe, and it basically wraps and depends on a static library A.lib

Both A.exe and A.lib need another library B.lib

If I have a situation like this:

The A.lib library includes B.lib version 1 (uses header files from this library) The A.exe executable includes B.lib version 2 The A.exe executable links against B.lib version 2

Under what conditions would this be problematic?

Thanks

+2  A: 

If the same functions exist in both B1.Lib and B2.Lib and both are linked to A.exe you may end up with a problem. Basically if B1::fn returns different results to B2::fn and A.Lib relies on the B1 results and A.exe relies on the B2 results you have a MAJOR problem. The linker will just link to the first implementation it finds and you can't be 100% sure that will be in B1 or B2.

Realistically its far safer to re-write A.lib to use B2.lib. Failing that namespaces are your friend ...

Goz
A.exe just links against a newer version of the lib. It does not use the older one at all.
ssm
Then you misunderstand how linking works. You don't link a ".lib" file. You only link a dynamic library or an executable. When you run the link stage on the executable then it will attempt to link everything together and the fact that you have 2 libraries in there that implement the same functionality means that you WILL end up linking the wrong functions together in one place or the other ...
Goz