C++ GCC ABI 兼容性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2801938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GCC ABI compatibility
提问by Fredrik Ullner
As far as I've understood, it is not possible to link libraries that use different versions of GCC's Application Binary Interface (ABI). Are there ABI changes to every version of GCC? Is it possible to link a library built with 4.3.1 if I use, say, GCC 4.3.2? Is there a matrix of some sort that lists all the ways I can combine GCC versions?
据我所知,不可能链接使用不同版本的 GCC 应用程序二进制接口 (ABI) 的库。GCC 的每个版本都有 ABI 更改吗?如果我使用 GCC 4.3.2,是否可以链接使用 4.3.1 构建的库?是否有某种矩阵列出了我可以组合 GCC 版本的所有方式?
采纳答案by ablaeul
The official ABI pagepoints to an ABIcheck. This tool may do, what you want.
回答by AProgrammer
Since gcc-3.4.0, the ABI is forward compatible. I.E. a library made using an older release can be linked with a newer one and it should work (the reverse doesn't). Obviously, there could be bugs, but there is only onementionned in the documentation: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33678
从 gcc-3.4.0 开始,ABI 是向前兼容的。IE 使用旧版本制作的库可以与新版本链接,它应该可以工作(反之则不行)。显然,可能存在错误,但文档中只提到了一个错误:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33678
回答by user3603401
Ugh, yikes.
How can you tell which gcc compiled a given binary? Here is the
death notice from gcc-4.7.2-1-mingw32.README.txt :
呃,哎呀。
你怎么知道哪个 gcc 编译了给定的二进制文件?这是来自 gcc-4.7.2-1-mingw32.README.txt 的死亡通知:
Binary incompatibility notice!
二进制不兼容通知!
The C and C++ ABI changed in GCC 4.7.0, which means in general you can't link together binaries compiled with this version of the compiler and with versions before GCC 4.7.0. In particular:
GCC 4.7.0 中的 C 和 C++ ABI 发生了变化,这意味着通常您无法将使用此版本编译器和 GCC 4.7.0 之前版本编译的二进制文件链接在一起。特别是:
The option -mms-bitfields is enabled by default, which means the bitfield layout follows the convention of the Microsoft compiler.
C++ class-member functions now follow the __thiscall calling convention.
The compiler now assumes that the caller pops the stack for the implicit arguments pointing to an aggregate return value. This affects functions returning structs by value, like the complex math type.
默认情况下启用选项 -mms-bitfields,这意味着位域布局遵循 Microsoft 编译器的约定。
C++ 类成员函数现在遵循 __thiscall 调用约定。
编译器现在假定调用者为指向聚合返回值的隐式参数弹出堆栈。这会影响按值返回结构的函数,例如复杂的数学类型。