Mixing different C++ standards with GCC

梦想的初衷 提交于 2019-11-30 03:51:37

问题


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:


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).



来源:https://stackoverflow.com/questions/38056849/mixing-different-c-standards-with-gcc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!