g ++总是向后兼容“旧”静态库? [英] g++ always backward-compatible with "older" static libraries?

查看:317
本文介绍了g ++总是向后兼容“旧”静态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些静态库,我不是所有者,用旧版本的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). so 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. Will is still work?

换句话说,
是g ++中的ABI更改只是链接向前兼容性的问题,

In other words, are ABI changes in g++ only an issue for linkage forward compatibility or can one get backward compatibility issues too?

谢谢。

推荐答案

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,它们在 std :: pair中有ABI不兼容性 std :: list 时使用C ++ 11,已在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 ++总是向后兼容“旧”静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆