开发者

Static libraries

开发者 https://www.devze.com 2023-04-11 11:35 出处:网络
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 SD

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 join everything together when I create DLL and symbols from SDK 1.0 override symbols from SDK 2.0 ??? (there aren't different namespaces).

Do you have any idea where is problem and is there any开发者_运维问答 solution ???

Thanks a lot!

I use Visual C++ 2010...


The behavior you observed is probably caused by the order in which libraries were listed in linker options. Try listing them in opposite order and you may well observe an "opposite" behavior.

I don't think you'll be able to mix-and-match libs that have same symbols like this. Your best bet is to wrap at least one of the libraries (or both) in separate DLL that would than expose different symbols to your "client" DLL (i.e. different namespaces or even different names).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号