C ++ 11与现有库/框架的兼容性 [英] C++11 compatibility with existing libraries/frameworks

查看:139
本文介绍了C ++ 11与现有库/框架的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



情况:




  • 一个带有一些库的系统(例如gtkmm)在没有c ++ 11的情况下编译。

  • 启用了使用C ++ 11编译的应用程序。

  • 两者都是使用相同的GCC版本/环境编译和链接的。

  • 应用程序对使用std :: string和std :: vector的库进行了一些函数调用。



std :: string和std :: vector支持移动语义,这很可能意味着它们不是与wth非C ++ 11变体二进制兼容的。但是,应用程序和库都使用相同的编译器和标准库来构建,所以如果lib能够识别并支持它,就不会那么奇怪。



上面的情况安全,或者真的需要使用C ++ 11标志来编译所有内容,即使使用相同的构建环境吗?

解决方案

页面专用于g ++ abi break与c ++ 11到版本4.7。
第一句话是:


C ++ 98语言与C ++ 11语言是ABI兼容的,但是库中的几个地方破坏兼容性。这使得链接C ++ 98对象和C ++ 11对象很危险。虽然有例子,启用c + + 11不会制止ABI兼容性:一个例子是Qt,你可以自由地混合c ++ 11支持使用c ++ 03构建版本。


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 ?

解决方案

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.

这篇关于C ++ 11与现有库/框架的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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