以可移植的方式将类导出到 dll,而不使用接口?
我有一个关于共享库/.dll 和类导入/导出的问题。经过一番研究后,我了解到有两种方法:
这是我所知道的仅有的两种方法。第一个是禁忌,因为它提供了 0 可移植性。第二个虽然对于实现目的的 .dll 来说是方便且良好的编程设计,但当您意识到需要为每个不同的构造函数有不同的构造函数时,它开始变得烦人,但只能使用 POD 类型作为参数,并且您会丢失许多C++ 类的优点,例如重载函数和默认函数参数。
对于应该向用户提供库的 .dll,例如类的集合,即使是第二种方式也变得非常不方便。所以我想知道这里的解决方案是什么?只是用第一种方法为每个主要编译器编译一个不同的.dll?大库的共享库版本如何工作?例如,wxWidgets 也提供了 .dll 版本。他们如何实现 .dll 的最终用户对类的正常使用,从而避免接口解决方案?
I have a question about shared libraries/.dlls and class importing/exporting. From what I have understood after some research the two ways to do it is as follows:
These are the only two ways I know. The first is a no-no since it offers 0 portability. The second, though convenient and a good programming design for a .dll that accomplishes a purpose starts to be annoying when you realize that you need to have a different constructor function for every different constructor, can only use POD types as parameters and you lose many advantages of C++ classes such as overloaded functions and default function arguments.
For a .dll that is supposed to offer a library to the user, a collection of classes for example even the second way becomes really inconvenient. So I am wondering what is the solution here? Just compile a different .dll with the first way for each major compiler? How do the shared libraries version of big libraries work? For example wxWidgets does offer a .dll version too. How do they achieve normal usage of classes by the end user of the .dll avoiding the interface solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为每个编译器版本提供单独的 DLL 的解决方案是有效的。同时它仍然不是官方功能。你永远不会知道下一个服务包是否会破坏兼容性,没有人会给你维持/破坏兼容性的编译器/链接器密钥的准确列表,等等。我听到可靠的传言说Windows8最终以正确的方式实现了这一点。
顺便说一下,仍然可以从以下位置下载 Visual Studio 2012 Release Candidate:http://msdn .microsoft.com/en-us/vstudio/bb984878.aspx。也许你应该尝试一下?
Solution with having separate DLL for each compiler version works. At the same time it is still not an official feature. You will never know if next service pack will break the compatibility or not, nobody will give you exact list of compiler/linker keys that will maintain/break the compatibility, etc. I heard reliable rumors that Windows8 finally implemented this in the right way.
By the way Visual Studio 2012 Release Candidate can be still downloaded from: http://msdn.microsoft.com/en-us/vstudio/bb984878.aspx. Maybe you should try it?