C++11 compatibility with existing libraries/frameworks

本秂侑毒 提交于 2019-12-01 15:18:23

问题


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 ?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/28201173/c11-compatibility-with-existing-libraries-frameworks

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