Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 针对不同版本的.dll的.lib进行链接可能会产生哪些副作用?_C++_C_Dll - Fatal编程技术网

C++ 针对不同版本的.dll的.lib进行链接可能会产生哪些副作用?

C++ 针对不同版本的.dll的.lib进行链接可能会产生哪些副作用?,c++,c,dll,C++,C,Dll,我正在针对较新的.lib进行链接,但在我的应用程序中使用较旧的.dll。这样做可能有什么副作用?如果两个版本之间的函数原型相同,那么一切都应该工作吗?如果较新版本更改了参数的默认值,该怎么办?该值是在.lib中还是在.dll中?默认参数应该在.h文件中,因此该部分可能没有问题 否则,当.DLL不能完成预期的操作时,可能的结果是通常很难找到错误。不要这样做。 我以前处理过“新库、旧DLL”问题,它们真的很烦人,很难诊断。只有当每个公开可见的类型都有完全相同的签名时才是“安全的”,这基本上意味着库作

我正在针对较新的.lib进行链接,但在我的应用程序中使用较旧的.dll。这样做可能有什么副作用?如果两个版本之间的函数原型相同,那么一切都应该工作吗?如果较新版本更改了参数的默认值,该怎么办?该值是在.lib中还是在.dll中?

默认参数应该在.h文件中,因此该部分可能没有问题


否则,当.DLL不能完成预期的操作时,可能的结果是通常很难找到错误。

不要这样做。

我以前处理过“新库、旧DLL”问题,它们真的很烦人,很难诊断。只有当每个公开可见的类型都有完全相同的签名时才是“安全的”,这基本上意味着库作者必须优先考虑二进制兼容性。否则,您将遇到奇怪的堆损坏错误,这些错误通常在程序运行一段时间后才会出现


回答您的特定问题:默认参数实际上是头文件的属性,而不是库。C++中的默认值< /P> < P>在调用站点编译-所以DLL或.LB文件将与此无关。更改标题将不会发生变化。 如果导出函数中的ABI没有改变,则只要程序没有使用新的.lib中的新导出,而不是旧的DLL中的新导出,就应该能够使用旧的DLL,并将程序链接到新的.lib中

影响ABI的因素(我不是说这是一个全面的列表):

“libtool版本控制系统”(http://www.gnu.org/s/libtool/manual/libtool.html#Versioning)是一种识别共享库兼容性的技术

请注意,如果您没有使用C调用约定(即导出名称将是“C++损坏”),那么从技术上讲,您对导出的名称几乎没有控制权


下面解释了一些Windows库(cygwin,pngdll)如何使用遵循libtool库版本控制技术的命名约定来管理向后兼容性。这是来自的web存档-我在这里镜像它:

有几个定义:

入口点是外部的 可访问的函数或变量 由DLL导出。界面是 所有这些文件的集合都已导出 给定函数中的函数和变量 库的版本。关于 中的libPNG版本宏 makefile.cygwin:

如果 新dll将删除一个 提供的旧dll。如果您添加一个新的 入口点,则新dll是 替换旧的, 因为新的能提供一切 老的那个

当然,根据 新版本,使用附加的 入口点,不适用于旧的 dll——但从来没有人答应过 向前兼容,仅向后兼容 兼容性。这就是cygwin的方式 DLL版本控制工作:

1) 遵循libtool版本控制 策划自 :

图书馆工具。换句话说,, 该库实现了所有 接口编号的范围为 number current-当前的年龄

Updating libtool versioning:

   1.     Start with version information of 0:0:0 for each libtool
图书馆

   2. Update the version information only immediately before a
公开的 发布您的软件。不需要更频繁的更新, 和 仅保证当前接口号变大 更快

   3. If the library source code has changed at all since the last
      update, then increment revision (c:r:a becomes c:r+1:a).

   4. If any interfaces have been added, removed, or changed since the
      last update, increment current, and set revision to 0.

   5. If any interfaces have been added since the last public release,
      then increment age.

   6. If any interfaces have been removed since the last public
      release, then set age to 0. 


Never try to set the interface numbers so that they correspond to the
release number of your package. This is an abuse that only fosters
misunderstanding of the purpose of library versions. Instead, use the
-release flag (see Release numbers), but be warned that every
释放 您的软件包与任何其他版本都不兼容

2) On windows/cygwin, the DLLVER is 'c - a' (trust me, this is correct,
但这更容易解释 示例)

这里有一个例子:libtool 版本为5:4:3,表示 第四次修订《公约》的执行情况 接口5,它恰好是 向后兼容三者 以前的接口定义。(即。 它对于链接的应用程序是安全的 针对接口5、4、3和2至 在运行时加载5:4:3 dll)

那么,让我们看看可能的历史 神秘的dll。我正在跟踪 c:r:a上面描述的更新规则

oldest: interface definition 0, initial release:
0:0:0 (DLLVER = 0)    
removed an entry point:
1:0:0 (DLLVER = 1)    NOT backwards compatible!
but DLLVER does the right thing.
source code changed, but no added or removed entry points:
1:1:0 (DLLVER = 1)    
more source code changes:
1:2:0 (DLLVER = 1)    

In all of the previous three releases, 'c' - 'a' = DLLVER = 1.
removed an entry point (or renamed it):
2:0:0 (DLLVER = 2)    This is INCOMPATIBLE.
(But look: 'c' - 'a' = 2, so the DLLVER does the right thing)
added a new function:
3:0:1 (DLLVER = 2)    (this is BACKWARDS but not FORWARDS compatible.
However, the DLLVER 'c' - 'a' still is 2, so that is good.)
add eight more exported functions all at once
4:0:2 (DLLVER = 2)    
add another function:
5:0:3 (DLLVER = 2)
source code changes, but no new interfaces:
5:1:3 (DLLVER = 2)    
again:
5:2:3 (DLLVER = 2)    
again:
5:3:3 (DLLVER = 2)    
again:
5:4:3 (DLLVER = 2)    
所有这些DLLVER=2的DLL (2:0:0, 3:0:1, 4:0:2, 5:0:3, 5:1:3, 5:2:3、5:3:3和5:4:3)都是 严格向后兼容:它是 保证 系列可以由以下exe加载: 是根据中的旧DLL编译的 这个系列

在1.2.3中,DLLVER为12。让我们 假设这是一个12的“c”-“a”, c=12,a=0

在[libpng]1.2.4中,您只需添加 一些新功能——但没有 删除任何。所以,新的libtool编号 是13:0:1,德尔弗仍然是12


如果且仅当旧版本和新版本的dll之间保持了二进制兼容性时,这就可以了

简单地说。如果:

  • 线束和线束使用的dll头文件没有任何更改
  • 没有添加或删除导出的符号,您可能不会有问题

如果这些条件中的任何一个都不满足,那么对于C++的VBIT来说,对于ABI的一部分,您将获得一些非常有趣的错误/崩溃/内存写潦草等。

,因此VTABLE(添加或删除的虚拟函数)中的任何更改都将导致二进制兼容性改变。
2) On windows/cygwin, the DLLVER is 'c - a' (trust me, this is correct,
oldest: interface definition 0, initial release:
0:0:0 (DLLVER = 0)    
removed an entry point:
1:0:0 (DLLVER = 1)    NOT backwards compatible!
but DLLVER does the right thing.
source code changed, but no added or removed entry points:
1:1:0 (DLLVER = 1)    
more source code changes:
1:2:0 (DLLVER = 1)    

In all of the previous three releases, 'c' - 'a' = DLLVER = 1.
removed an entry point (or renamed it):
2:0:0 (DLLVER = 2)    This is INCOMPATIBLE.
(But look: 'c' - 'a' = 2, so the DLLVER does the right thing)
added a new function:
3:0:1 (DLLVER = 2)    (this is BACKWARDS but not FORWARDS compatible.
However, the DLLVER 'c' - 'a' still is 2, so that is good.)
add eight more exported functions all at once
4:0:2 (DLLVER = 2)    
add another function:
5:0:3 (DLLVER = 2)
source code changes, but no new interfaces:
5:1:3 (DLLVER = 2)    
again:
5:2:3 (DLLVER = 2)    
again:
5:3:3 (DLLVER = 2)    
again:
5:4:3 (DLLVER = 2)