C++动态链接库的兼容性

本文详细探讨了C++动态链接库的ABI兼容性问题,包括删除导出类、改变函数签名等行为如何导致不兼容,以及增加非虚函数、改变默认参数等一般不会引起不兼容的情况。并提供了在设计跨平台C++代码时的建议和注意事项。
摘要由CSDN通过智能技术生成

一.动态链接库的ABI

    动态链接库的兼容性是由于库的ABI(Application binary interface)引起,ABI与API类似,但是主要包括一些诸如函数调用的堆栈结构、符号命名、参数规则、数据结构的内存分布等方面的规定。


二.引起动态链接库不兼容的行为

  • 删除一个导出类;
  • 改变导出类的继承层次
  • 改变模板的模板参数
  • 删除一个导出函数
  • 改变函数的inline属性
  • 改变函数的签名
  • 在一个非虚基类或者没有含有虚函数的类中添加一个虚函数
  • 改变虚函数的声明次序
  • ......


三.一般不会引起动态链接库不兼容的行为

  • 增加一个非虚函数
  • 删除没有被inline函数调用的非虚函数
  • 改变一个函数的默认参数
  • 增加新的static数据成员
  • 导出一个新的参数
  • 增加或者删除一个友元声明
  • ......


四.详细的内容(英文)

    详细的内容可以参考:https://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C++

Note about ABI

This text applies to most C++ ABIs used by compilers which KDE can be built with. It is mostly based on the Itanium C++ ABI Draft, which is used by the GCC C++ compiler since version 3.4 in all platforms it supports. Information about Microsoft Visual C++ mangling scheme mostly comes from this article on calling conventions (it's the most complete information found so far on MSVC ABI and name mangling).

Some of the constraints specified here may not apply to a given compiler. The goal here is to list the most restrictive set of conditions when writing cross-platform C++ code, meant to be compiled with several different compilers.

This page is updated when new binary incompatibility issues are found.

The Do's and D

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值