g++ 总是向后兼容“older";静态库?

g++ always backward-compatible with quot;olderquot; static libraries?(g++ 总是向后兼容“older;静态库?)
本文介绍了g++ 总是向后兼容“older";静态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些静态库,但我不是其所有者,它们是用旧版本的 g++ 4.3.2 编译的(c++11/c++0x 未激活).

I have a few static libraries, which I'm not the owner of, compiled with an old version of g++ 4.3.2 (c++11/c++0x not activated).

当我使用 g++ 4.6(没有 c++11)编译我的代码并使用 g++ 4.6 将其与这些链接时静态库,它链接很好,我似乎在运行时没有遇到任何问题(虽然没有测试一切).我倾向于认为前向兼容性是可以的.

When I compile my code with g++ 4.6 (no c++11) and link it using g++ 4.6 with these static libraries, it links fine and I do not seem to get any issues at runtime (not tested everything though). I'm tempted to think that forward compatibility is OK.

现在我想用 gcc 4.8 和 c++11 编译我的代码,并且仍然将它与那些相同的、未重新编译的静态库链接.

Now I'd like to compile my code with gcc 4.8 with c++11 and still link it with those same, not recompiled static libraries.

g++ 中的 ABI 更改是否只是链接向前兼容性的问题,还是也可能出现向后兼容性问题?

推荐答案

G++ ABI for C++98 代码向后兼容,一路回溯到 GCC 3.4

The G++ ABI for C++98 code is backward compatible, all the way back to GCC 3.4

因此,如果您使用 GCC 4.8 编译和链接您的最终可执行文件,您可以链接到使用 GCC 3.4 到 4.8(但没有更新版本)构建的对象和库

So if you compile and link your final executable with GCC 4.8 you can link to objects and libraries built with anything from GCC 3.4 to 4.8 (but no newer)

C++11 ABI 与 C++98 ABI 相同,C++98 和 C++11 通用的标准库类型具有相同的定义,(忽略 GCC 4.7.0 和 GCC 4.7.1,在使用 C++11 时在 std::pairstd::list 中存在 ABI 不兼容问题,已在 4.7 中修复.2 和更高版本),以便您可以将 C++98 和 C++11 代码链接在一起(除非 C++11 代码是使用 GCC 4.7.0 或 4.7.1 构建的)

The C++11 ABI is the same as the C++98 ABI and the standard library types that are common to both C++98 and C++11 have the same definitions, (ignoring GCC 4.7.0 and GCC 4.7.1, which had ABI incompatibilities in std::pair and std::list when using C++11, which have been fixed in 4.7.2 and later versions) so you can link C++98 and C++11 code together (unless the C++11 code was built with GCC 4.7.0 or 4.7.1)

然而一些 C++11 库类型还不稳定,并且会在不同版本之间发生变化,例如因为它们是在最终的 C++11 标准之前首次发布的,并且必须进行更改以匹配最终规则.所以混合使用 GCC 4.6 构建的 C++11 代码和使用 GCC 4.8 构建的 C++11 代码不一定安全

However some C++11 library types are not stable yet and change between releases, e.g. because they were first shipped before the final C++11 standard and had to be changed to match the final rules. So it's not necessarily safe to mix C++11 code built with GCC 4.6 and C++11 code built with GCC 4.8

对于您的情况,所有 C++11 代码都是使用 GCC 4.8 构建的,这没问题.如果您升级编译器,您应该使用较新的 GCC 重新构建所有 C++11 代码以确保安全.(C++98/C++03代码不需要重新编译)

For your case, where all the C++11 code is built with GCC 4.8 that will be OK. If you upgrade the compiler you should rebuild all the C++11 code with the newer GCC to be safe. (You don't need to rebuild the C++98/C++03 code)

这篇关于g++ 总是向后兼容“older";静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)