9

我的(C++,跨平台)应用程序大量使用Boost库(比如 version 1.x),我还想链接到第 3 方(供应商)的 SDK(无源),它本身使用Boost(但 version 1.y)。

因此,我们都动态链接到我们自己的BoostDLL 版本,CRT 是相同的。因此,在运行时,我的应用程序必须同时加载Boost 1.x & 1.y.

有哪些潜在问题和相关问题?

我无法更改供应商的 SDK,但我可以更改我的应用程序。也许我应该尝试静态链接我的Boost 1.x?

PS:Boost的 DLL 的名称包括它们的版本,所以没有名称冲突,两者都是可识别的。不是通常的 DLL 地狱。

4

3 回答 3

2

This is a big problem. Do a search on DLL hell.

Basically the DLL (or shared libs in Linux) are loaded but not all the names are resolved at load time. What happens is a lazy evaluation, so the names are evaluated on first use. The problem is that if 2 dll have the same name then the location where the name is resolved to depends on the what order the DLL are searched in (which depends on load order).

If you statically link then you will not have problems with method calls as yours will all be resolved at compile time and the third party will be resolved at runtime from the DLL. But what about structures that are created by version-1 boost. If you then pass these to the third party library that then passes it to the version-x boost. Are the structures layed out in the same way?

This is a very tricky area and when problems occur very hard to de-bug. So try and use the same version.

于 2009-03-27T18:01:52.177 回答
2

至于使用不同版本的DLL应该没有问题。至少在 Windows 上没有。

如果 SDK 在内部使用 boost,这是真的。如果 SDK 在其接口中使用 boost 构造,例如:它有一个返回 boost::optional 的函数,那么拥有多个版本可能会导致问题。它仍然可以正常工作,具体取决于版本之间的更改,但这肯定会有风险。在这种情况下,我不知道有什么好的解决方案。如果您包含一个包含 boost 头文件的 SDK 头文件,这也是如此。

于 2009-03-27T13:51:27.007 回答
0

如果你写一个函数foo,然后从 F.dll 中导出它,然后从 G.dll 中导出另一个函数foo,你会期待问题吗?

当 AF.exe 被链接时,链接器被告知:放一些代码foo从 F.dll 加载函数的地址。现在 BG.dll 被链接以foo从 G.dll 中检索地址。我仍然认为没有问题。

现在将 AF.exe 替换为您的应用程序,将 BG.dll 替换为您供应商的应用程序,将 F.dll 替换为您的 boost 版本,将 G.dll 替换为供应商的 boost 版本。

结论:如果 dll 名称不同,我认为没有问题。

于 2009-03-27T13:34:43.537 回答