10

I am wondering something for which I have not found a convincing answer yet.

Situation:

  • A system with some libraries (e.g. gtkmm) compiled without c++11 enabled.
  • An application compiled with C++11 enabled.
  • Both are compiled and linked with the same GCC version/environment.
  • The application has some function calls to the library which use std::string and std::vector.

both std::string and std::vector support move semantics which most likely mean they are not binary compatible with wth non C++11 variants. However both the application and library are build with the same compiler and standard libraries, so it would not be so strange if the lib would recognize this and support it.

Is the above situation safe, or would it be really required to compile everything with the C++11 flag, even if the same build environment is used ?

Waldorf
  • 833
  • 2
  • 13
  • 24
  • I know that I've built the Boost libraries without C++11 support, and then tried to link a small application to them that did have C++11 support. I don't remember the exact manifestation of the problem, but in the end linking would *not* work until I rebuilt the Boost libraries with the support. – Steve Jan 28 '15 at 20:07
  • I did a bit of searching and found this, which sounds a lot like the problem I referred to in the previous comment. Looks like it might have been a bug in Boost and not evidence for what you're looking for. Take a look and decide for yourself :) https://svn.boost.org/trac/boost/ticket/10038 – Steve Jan 28 '15 at 20:12
  • 1
    I think [this question](http://stackoverflow.com/q/12637699/1708801) answers question. – Shafik Yaghmour Jan 28 '15 at 20:36
  • Related: https://stackoverflow.com/a/49119902/23715 – Alex Che Sep 21 '18 at 11:23

2 Answers2

5

This page is dedicated to g++ abi breaks with c++11 up to version 4.7. The first sentence there is:

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.

Though there are examples, where enabling c++11 won't brake ABI compatibility: one example is Qt where you can freely mix c++11 enabled builds with c++03 builds.

UldisK
  • 1,619
  • 1
  • 17
  • 25
3

You can consider each translation of C++ by a different compiler (even if the compiler is the same, but has a different (minor) version) incompatible. C++ has no common application binary interface (ABI).

In addition, a change of the dialect supported by the compiler is a change of the ABI, hence the resulting libraries are incompatible. An obvious example is a release build vs. debug build, where the debug data structures introduce additional members.

And moving structures (C++11) or not moving structures ( < C++11) is a radical change of the ABI.

  • I would disagree that adding non virtual function change anything in the ABI. Problem is function signature change and changes of data members. – UldisK Jan 28 '15 at 20:51
  • OP specifically asks about GCC, which has it's own ABI compatibility policies. – Alex Che Sep 21 '18 at 11:07