Mixing different C++ standards with GCC

2019-04-24 15:58发布

问题:

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