Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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 Frown | :(
 
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 ??? Frown | :(
 
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 8-Oct-11 7:52am
ExeCom124
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
SafarTimura at 10-Oct-11 6:38am
   
Yes this will solve the problem. + 5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use GetProcAddress[^] to specify which one to use.
  Permalink  
Comments
CPallini at 8-Oct-11 16:38pm
   
AFAIK you cannot use it with a static library's function.
ExeCom at 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 ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 459
1 Nirav Prabtani 338
2 Abhinav S 170
3 PIEBALDconsult 160
4 Pikoh 140
0 OriginalGriff 7,640
1 Sergey Alexandrovich Kryukov 6,836
2 Maciej Los 3,919
3 Peter Leow 3,698
4 CHill60 2,742


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 9 Oct 2011
Copyright © CodeProject, 1999-2014
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