views:

38

answers:

1

I have an old c++ project compiled with VC6.

I need to statically link a new library to implement a new functionality.

Unfortunately the new library define a symbol (i.e. _inflate) that is already defined in a previously linked static library.

Of course I cannot get rid of either library, and of course I have no access to the library's source code.

Is there a way to avoid the linker error (LNK2005)?

+3  A: 

If you know that the two versions of _inflate are identical, or at least "compatible", then you can use the /FORCE:Multiple linker option to force it to ignore name clashes.

Of course, if it links to a version of that code that is "incompatible" in any way it could cause undefined behaviour.

Jason Williams
well, I was able to compile...but since I'm not sure about _inflate implementation I have to find another solution (maybe dinamically link one of the two). thanks
Stefano
The easiest approach is to force a link and then test the program. If your program never directly or indirectly causes _inflate to be called, there will be no problem. If _inflate is called but the implementation is similar enough (or doesn't affect other program state) then it may not cause any undesireable effects (often you'll find two identical implementaiotns in different libs). If it does get called and is "incompatible", then you'll likely get a massive and very obvious failure. So I'd try it, and if it all runs fine in testing, you probably have a workable solution.
Jason Williams