且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++ 11和C ++ 03之间的库兼容性

更新时间:2023-01-10 20:42:18

标准库已更改,并且 -std = c ++ 0x 编译器标志将确定正在使用库的哪个部分。通过尝试在同一程序中使用两个版本,您正在打破一个定义规则(对于标准库中的每个已使用元素,您都具有相同标识符的两个定义)。

The standard library has changed, and the -std=c++0x compiler flag will determine what part of the library is in use. By trying to use both versions in the same program you are breaking the One Definition Rule (for each used element in the standard library you have two definitions for the same identifier).

我认为没有什么简单的方法可以克服此限制。您将必须确保只使用该库的一个版本(即,在包含标准头以在这些库中禁用C ++ 11之前定义适当的宏),即使如此,我仍然不确定所生成的代码是否仍不会打破ODR(如果C ++ 11扩展对C ++ 03库代码的编译方式不同)。

I don't think there is anything simple that can be done to overcome this limitation. You would have to ensure that you only use one version of the library (i.e. define the appropriate macros before inclusion of standard headers to disable C++11 inside those libraries), and even then I am not sure that the generated code would still not break the ODR (if the C++11 extensions compile the C++03 library code differently).