如何在dll中使用静态成员和单例?
实际上,我正在研究 Linux 项目的 Windows (MSYS/MinGW) 迁移。在 Linux 中,一切工作正常,但在 Windows 中,我遇到了静态成员和单例的麻烦,它们必须在不同 dll 的上下文中使用。
即我有一个配置映射器,它是 config.dll 中的单例构建。如果我在与其他 dll 不同的内部使用此 dll,则任何 dll 都有它自己的实例。有没有办法在这些 dll 之间共享单例访问?
我在 dll 之间使用静态成员也失败了。如果我从任何其他 dll 调用放置在 math.dll 中的向量类的静态成员,我在 make 期间收到此消息:
Linking CXX shared library ../../lib/libbrGraphics.dll
Info: resolving binrev::brMath::brVector3f::NEGATIVE_UNIT_Z by linking to
__imp___ZN6binrev6brMath10brVector3f15NEGATIVE_UNIT_ZE (auto-import)
知道有人有解决方案吗? 此致, 克里斯
actually i'm working on a windows (MSYS/MinGW) migration of our Linux project. With Linux everything works fine, but with windows i got trouble with static members and singletons which have to be used over the context of different dlls.
I.e. I've an configuration mapper, which is a singleton build in a config.dll. If i use this dll inside differnd other dll, any dll got it's own instance. Is there a way to share the singleton access between those dlls?
I got also a failure using static members between dlls. If i call a static member of an vector class wich is placed in math.dll from any other dll i got this message during make:
Linking CXX shared library ../../lib/libbrGraphics.dll
Info: resolving binrev::brMath::brVector3f::NEGATIVE_UNIT_Z by linking to
__imp___ZN6binrev6brMath10brVector3f15NEGATIVE_UNIT_ZE (auto-import)
Knowes anyone a solution?
Best regards,
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DLL 是一个库,如果您想共享配置数据,您必须将单例映射到共享内存映射上或使用其他一些 RPC 机制。您不会期望其他计算机上的错误日志中会包含您打印到 stderr 的内容,对吧?
A DLL is a library, if you want to share configuration data you will have to map the singleton on a shared memory map or use some other RPC mechanism. You wouldn't expect the error log on someone else's computer to be filled with what you print to stderr would you?