Click here to Skip to main content
15,867,972 members
Articles / Programming Languages / C++
Tip/Trick

How to build an image (DLL/EXE) when two of its included libraries have the same symbol (say function/variable) using VC++

Rate me:
Please Sign up or sign in to vote.
3.38/5 (8 votes)
24 Jan 2012CPOL 43.4K   5   11
How to build an image (DLL/EXE) when two of its included libraries have the same symbol (say function/variable) using VC++
Say we are building an EXE which utilizes two static libraries, external_1.lib and external_2.lib.

external_1.lib has two functions FunA() and FunB(),
while external_2.lib has FunA() and FunC().
Note: FunA() is there in both the libs !!!, which is practical in the real world.

Now in our EXE's main(), we have code like shown below:

C++
void main()
{
   FunB(); // from external_1.lib
   FunC();  // from external_2.lib
  
   FunA();  // from external_1.lib / external_2.lib ????
}


The compiler will obviously throw a linker error saying that FunA is there in multiple objs.

If both these libs are of 3rd party, then we cannot compile them. How to resolve this ??

Simple. Use the linker option
/FORCE:MULTIPLE

Check this link:
http://msdn.microsoft.com/en-us/library/70abkas3.aspx[^]

License

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


Written By
Technical Lead
India India
_____________________________________________________________

Did my masters from IIT-M in Advanced Manufacturing Technology and working mainly on C++ in CAD domain from 2004 onwards.
Working on web technologies using Angular 7.0 and above, HTML5, CSS3 from 2015.

Comments and Discussions

 
General[My vote of 1] Shutting up the linker does not solve your problem Pin
.:floyd:.21-Mar-14 5:19
.:floyd:.21-Mar-14 5:19 
GeneralRe: [My vote of 1] Shutting up the linker does not solve your problem Pin
Lakamraju Raghuram28-Mar-14 1:44
Lakamraju Raghuram28-Mar-14 1:44 
GeneralRe: [My vote of 1] Shutting up the linker does not solve your problem Pin
.:floyd:.30-Mar-14 10:22
.:floyd:.30-Mar-14 10:22 
GeneralRe: [My vote of 1] Shutting up the linker does not solve your problem Pin
Lakamraju Raghuram31-Mar-14 22:05
Lakamraju Raghuram31-Mar-14 22:05 
GeneralRe: [My vote of 1] Shutting up the linker does not solve your problem Pin
.:floyd:.3-Apr-14 10:23
.:floyd:.3-Apr-14 10:23 
GeneralReason for my vote of 3 Now i know! Pin
Sampson Wei28-Jan-12 23:15
Sampson Wei28-Jan-12 23:15 
GeneralReason for my vote of 5 Good to know, I would never have ima... Pin
YvesDaoust23-Jan-12 20:39
YvesDaoust23-Jan-12 20:39 
GeneralHmmm...correct but an addition: We should not again use this... Pin
Lakamraju Raghuram23-Jan-12 17:42
Lakamraju Raghuram23-Jan-12 17:42 
GeneralReason for my vote of 1 You can write your own wrapper for o... Pin
dvpsun23-Jan-12 17:13
dvpsun23-Jan-12 17:13 
GeneralJon, I am speaking about the hopeless case, where we don't ... Pin
Lakamraju Raghuram23-Jan-12 15:00
Lakamraju Raghuram23-Jan-12 15:00 
GeneralReason for my vote of 2 Not a resolution. May cause chaos. Pin
Jon Summers23-Jan-12 7:33
Jon Summers23-Jan-12 7:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.