Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a problem with static libraries. I need to use 2 different versions of the same SDK in one DLL without names collisions. I thought that solution is to make 2 static libs for every version of SDK and then import these libs to DLL. But this solution works strange and I'm not sure why....

simplified situation looks like this:

LIB1 - there is function Add1 which uses things from SDK 1.0

LIB2 - there is function Add2 which uses things from SDK 2.0

DLL- imports LIB1 and LIB2 and there is function Add(float version) which calls Add1 or Add2 - depends on version number in parameter

Compilation process is OK but DLL works only with one version SDK :(

When I debug it I see that program calls Add function from DLL with version 2.0 in parameter. Then Add really calls Add2 - so this is still right. BUT then inside Add2 function it uses things which are defined in SDK 1.0 instead of SDK 2.0 ! LIB2 is really created with SDK 2.0. (include dirs and lib dirs are set to SDK 2.0)

So why it uses SDK 1.0 ??? :(

Is it because of linker which joins everything together when I create DLL and symbols from SDK 1.0 override symbols from SDK 2.0 ??? (SDKs don't have different namespaces).

Do you have any idea where is problem and is there any solution ???

Thanks a lot!

I use Visual C++ 2010...
Posted

It certainly looks like LIB2 is wrongly linking to SDK 1.0.
Here is what I would try to do -
Install only SDK 2.0 and build only LIB2.
If this works, we can try to install both SDK 1.0 and 2.0 and build only LIB2.
I believe that this way we could narrow down the cause of the problem.
 
Share this answer
 
You will always have a problem with this if there are any names which exist in both LIB1 and LIB2. As suggested above you would be better to make these both DLLs and use LoadLibrary and GetProcAddress to select the correct functions.
 
Share this answer
 
Comments
Guyverthree 10-Oct-11 6:38am    
Yes this will solve the problem. + 5
Use GetProcAddress[^] to specify which one to use.
 
Share this answer
 
Comments
CPallini 8-Oct-11 16:38pm    
AFAIK you cannot use it with a static library's function.
ExeCom 8-Oct-11 16:42pm    
GetProcAdress ???????

Add1 and Add2 are in static libs and there isn't any problem with calling them.... There is problem inside them. How do you want to choose SDK with getprocadress ??? SDK is a lot of *.h and *.lib files with declarations and definitions. I don't understand. how do you think it ?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900