用GCC混合不同的C ++标准 [英] Mixing different C++ standards with GCC

查看:152
本文介绍了用GCC混合不同的C ++标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况:

有两个组件,一个用C ++编写,另一个用C ++编写。
两者都是使用相同的GCC 4.9从头开始编译的。一个使用隐式默认 - std = gnu ++ 98 另一个显式设置 - std = c ++ 11

即使在做了一些研究后,我也无法完全回答这个问题是否可能导致问题。



GCC wiki 说:


C ++ 98语言与C ++ 11语言是ABI兼容的,但库中的一些地方会兼容性。这使得将C ++ 98对象与C ++ 11对象链接起来非常危险。如果你可以用匹配的语言版本重新编译你的代码,你应该这样做。


这表明问题是可以预料的。



所以问题是:


  1. 使用 - std = gnu ++ 98 - std = c ++ 11 构建的两个组件链接在一起,甚至很难使用相同的 libstdc ++ 并使用相同的编译器(GCC 4.9)构建?

  2. 在这种情况下,GCC 5.1的 Dual ABI 支持是否会产生影响?



解决方案

1)例如,



2)是的。



我会重新编译所有内容中的一个两个c ++版本。如果这不是一个选择(第三方库等)使用双重ABI机制可能是一个解决方案。请注意不同版本的代码之间共享的内容。



您提到的wiki的部分内容涉及例如旧代码尝试做的事情不再支持(语义不同但语法相同)。

I have the following scenario:

There are two components one is written in C++11 the other in C++98. Both are compiled from scratch using the same GCC 4.9. One uses the implicit default --std=gnu++98 the other explicitly sets --std=c++11.

Even after doing some research I could not completely answer the question if this could cause issues.

The GCC wiki says:

The C++98 language is ABI-compatible with the C++11 language, but several places in the library break compatibility. This makes it dangerous to link C++98 objects with C++11 objects. If you can recompile your code in matching versions of the language, you should do that.

This suggest that problems are to be expected.

So the questions are:

  1. Are there issues if the two components built with --std=gnu++98 and --std=c++11 are linked together, even tough they use same libstdc++ and are built with the same compiler (GCC 4.9)?

  2. Does Dual ABI support form GCC 5.1 have an influence in that case?

解决方案

1) There may be issues since, for example, the implementation of some part of the lib you mentioned changed.

2) Yes.

I would recompile everything in one of the two c++ version. If that is not an option (third party library etc.) using the dual ABI mechanism could be a solution. Be very careful on what it's shared between different version of the code.

The part of the wiki you mentioned talks about situations where, for example, old code tries to do stuff that is no longer supported (different semantic but same syntax).

这篇关于用GCC混合不同的C ++标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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