Click here to Skip to main content
13,007,704 members (84,337 online)
Rate this:
 
Please Sign up or sign in to vote.
Hi,

I am linking two Third party libs in my application. (Both libs are from different vendors)
I am getting the following error

1>slic.lib(xmllsp.obj) : error LNK2005: _endElement already defined in libxml_mdd.lib(legacy.obj)
1>slic.lib(xmllsp.obj) : error LNK2005: _startElement already defined in libxml_mdd.lib(legacy.obj)
1>libadt_mdd.lib(list.obj) : error LNK2005: _list_init already defined in slic.lib(s_list.obj)
1>libadt_mdd.lib(list.obj) : error LNK2005: _list_remove already defined in slic.lib(s_list.obj)


I know that this error comes when Linker found same symbol at multiple locations.

How to resolve this, as both libs i am using are third party, i dont have control on its code.

Thank you,

Prafulla Vedante
Posted 25-Feb-14 23:48pm
Updated 26-Feb-14 1:31am
v3
Comments
Albert Holguin 26-Feb-14 10:36am
   
Not sure if it would make a difference... just thinking here... but are these static or dynamic libraries? ...wondering if you could possibly wrap the libraries in another library so the namespaces are completely separate (since the global namespace of a dll is independent of the calling exe), it would be a hassle but that may work.
PrafullaVedante 27-Feb-14 1:48am
   
libxml_mdd.lib is a static library.

You are right. We can get rid of this problem using a wrapper dll. I am going ahead with this approach as a workaround. Will investigate more once i finish the work.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Check the full error message: it should list the symbols that are multiply defined as well as the object files (or libs) that defined them. The symbols may be obfuscated: If you have trouble identifying them, I strongly suggest you copy&paste the full error message here.

P.S.: after checking on the library names, I realized that there are three, two of which are .NET libraries. You spoke of two third party libraries, so I take it slic.lib is yours? If so, then maybe you made an error when creating slic.lib. Either you accidentally defined symbols already being used in those .NET libs (unlikely), or you statically bound the .NET libs to that lib as well. In the latter case, you'd have two instances of the libs in the final exe! In any case you might want to check xmllsp.cpp and s_list.cpp from your slic.lib.
  Permalink  
v2
Comments
PrafullaVedante 26-Feb-14 7:31am
   
I have updated the question with full error.
Stefan_Lang 26-Feb-14 9:52am
   
Sorry, I meant to post this as a comment, not a solution. Looks like the three libraries slic, libxml_mdd, and libadt_mdd really are in conflict.

You could try the /FORCE:MULTIPLE command line option for the linker. This will make it use the first symbol definition and ignore any others that are around. If the definitions are the same, it might just work. If not, I really can't say: a good guess is to check if you use the symbols, and if so, which definition; then make sure that the library containing the definition you use before the others on the linker command line.
PrafullaVedante 27-Feb-14 1:46am
   
/FORCE:MULTIPLE is a worse solution i guess. Because these definitions are coming from three different libraries, and we dont know if they are same. Its more probable that they are different symbols with same name.
Stefan_Lang 27-Feb-14 2:43am
   
I agree that /FORCE:*anything* is likely not a good solution. It's just the only one I can think of, and without seeing the libraries in question and your linker settings it's hard to tell what is the actual problem.

But as I stated in my PS statement: isn't slic.lib *your* library? This library causes conflicts with both other libraries, so it may be just this lib that is defective!

Some other thing that came to my mind is namespaces: any decent library should wrap their symbols in its own namespace to avoid conflicts with other libraries. You might however negate that wrapper by introducing using statements for these namespaces in your program! Doing so can lead to name clashes like the ones you are reporting here. Please check your program if it has using statements, especially in header files, and *remove* them!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170628.1 | Last Updated 26 Feb 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100