STL容器和二进制接口兼容性 [英] STL Containers and Binary Interface Compatibility

查看:154
本文介绍了STL容器和二进制接口兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,是否有人在跨多个C ++编译器和平台的STL对象的兼容接口层上工作.

I'm curious to know if anyone is working on compatible interface layers for STL objects across multiple compilers and platforms for C++.

目标是支持将STL类型作为第一类或固有数据类型.

The goal would be to support STL types as first-class or intrinsic data types.

通常通过模板施加一些固有的设计限制来防止这种情况吗?这似乎是使用STL进行二进制分发的主要限制.

Is there some inherent design limitation imposed by templating in general that prevents this? This seems like a major limitation of using the STL for binary distribution.

  1. Microsoft已将精力投入到.NET中,并不太在乎C ++ STL支持是否是一流".

  1. Microsoft has put effort into .NET and doesn't really care about C++ STL support being "first class".

开放源代码不希望推广仅二进制的分发,而是致力于通过单个编译器来解决问题,而不是不匹配10个不同版本.

Open-source doesn't want to promote binary-only distribution and focuses on getting things right with a single compiler instead of a mismatch of 10 different versions.

我对Qt和其他库的经验似乎支持了这一点-它们通常为您将要使用的环境提供构建.例如Qt 4.6和VS2008.

This seems to be supported by my experience with Qt and other libraries - they generally provide a build for the environment you're going to be using. Qt 4.6 and VS2008 for example.

参考:

  • http://code.google.com/p/stabi/
  • Binary compatibility of STL containers

推荐答案

我认为问题出现的依据是您的理论:C ++未指定ABI(应用程序二进制接口).

I think the problem preceeds your theory: C++ doesn't specify the ABI (application binary interface).

事实上,即使C也不是,但是作为C库只是函数的集合(可能是全局变量),ABI只是函数本身的名称.取决于平台,名称可以通过某种方式进行修改,但是,由于每个编译器都必须能够进行系统校准,因此所有内容最终都使用操作系统构建器的相同约定(在Windows中,_cdecl只会导致在到函数名称.

In fact even C doesn't, but being a C library just a collection of functions (and may be global variables) the ABI is just the name of the functions themselves. Depending on the platform, names can be mangled somehow, but, since every compiler must be able to place system calss, everything ends up using the same convention of the operating system builder (in windows, _cdecl just result in prepending a _ to the function name.

但是C ++具有重载,因此需要更复杂的处理方案. 到目前为止,编译器制造商之间尚无关于如何进行这种整顿的协议. 从技术上讲,不可能编译C ++静态库并将其链接到来自另一个编译器的C ++ OBJ. DLL也是如此.

But C++ has overloading, hence more complex mangling scheme are required. As far as of today, no agreement exists between compiler manufacturers about how such mangling must be done. It is technically impossible to compile a C++ static library and link it to a C++ OBJ coming from another compiler. The same is for DLLs.

而且,即使对于已编译的重载成员函数,编译器也各不相同,因此实际上没有人提供模板问题.

And since compilers are all different even for compiled overloaded member functions, no one is actually affording the problem of templates.

从技术上讲,它可以通过为每种参数类型引入重定向并引入调度表来提供,但是...这使得模板化函数(就呼叫调度而言)与虚拟库的虚拟函数没有区别,从而使模板性能提高变得类似于经典的OOP调度(尽管它可以限制代码膨胀,但折衷并不总是很明显)

It CAN technically be afforded by introducing a redirection for every parametric type, and introducing dispatch tables but ... this makes templated function not different (in terms of call dispatching) than virtual functions of virtual bases, thus making the template performance to become similar to classic OOP dispatching (although it can limit code bloating ... the trade-off is not always obvious)

现在,似乎编译器制造商之间没有必要同意一个通用标准,因为这将牺牲每个制造商通过自己的优化可以拥有的所有性能差异.

Right now, it seems there is no interest between compiler manufacturers to agree to a common standard since it will sacrifice all the performance differences every manufacturer can have with his own optimization.

这篇关于STL容器和二进制接口兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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