静态库问题 [英] static libraries problem

查看:60
本文介绍了静态库问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对静态库有疑问.我需要在一个DLL中使用同一SDK的2个不同版本,而不会发生名称冲突.我认为解决方案是为每个版本的SDK创建2个静态库,然后将这些库导入DLL.但是此解决方案的工作方式很奇怪,我不确定为什么....

简化的情况如下所示:

LIB1-有功能Add1,它使用SDK 1.0中的功能

LIB2-有功能Add2,它使用SDK 2.0中的功能

DLL-导入LIB1和LIB2,并且具有函数Add(浮动版本),该函数调用Add1或Add2-取决于参数中的版本号

编译过程还可以,但DLL仅适用于一个版本的SDK :(

当我调试它时,我看到程序从DLL中调用带有参数2.0版的Add函数.然后Add实际上会调用Add2-因此这仍然是正确的.但是,在Add2函数内部,它使用的是SDK 1.0中定义的内容,而不是SDK 2.0中定义的内容! LIB2实际上是使用SDK 2.0创建的. (包括dirs和lib dirs设置为SDK 2.0)

那么为什么要使用SDK 1.0? :(

是因为链接器在我创建DLL时将所有内容连接在一起,而SDK 1.0中的符号覆盖了SDK 2.0中的符号? (SDK没有不同的名称空间).

您知道哪里出问题了,有什么解决办法吗?

非常感谢!

我使用的是Visual C ++ 2010 ...

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

推荐答案

如果LIB1和LIB2中都存在任何名称,您将始终会遇到问题.如上面的建议,最好同时制作这两个DLL,并使用LoadLibraryGetProcAddress选择正确的函数.
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.


使用GetProcAddress [
Use GetProcAddress[^] to specify which one to use.


肯定看起来LIB2错误地链接到SDK 1.0.
这是我会尝试做的-
仅安装SDK 2.0并仅构建LIB2.
如果可行,我们可以尝试同时安装SDK 1.0和2.0并仅构建LIB2.
我相信通过这种方式,我们可以缩小问题原因的范围.
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.


这篇关于静态库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆