在C或C实现插件系统++ [英] Implementing A Plugin System in C or C++
问题描述
你对实现插件式的系统提示吗?
What are your tips on implementing a plugin style system?
推荐答案
在C(我认为C ++太虽然我没有做我自己),这是使用动态加载模块最典型的完成。该API:S对于如依赖于平台的
In C (and I think C++ too although I haven't done it myself), this is most typically done using dynamically loaded modules. The API:s for such are platform-dependent.
在POSIX(Linux)的,您可以使用 dlopen()的
系列函数。基本上你单独建立自己的插件,然后在运行时加载它,通过名称来查找它的符号,然后可以给他们打电话。
On POSIX (Linux), you use the dlopen()
family of functions. Basically you build your plugin separately, then load it at run-time, look up its symbols by name, and can then call them.
对于Win32,有 调用LoadLibrary()
这确实非常类似的东西,你建立你的code到DLL。
For Win32, there is LoadLibrary()
which does something very similar, you build your code into a DLL.
有关一个方便的包装,使所有的这些简单而透明,检查GLib的的的 GModule API。
For a handy wrapper that makes all of these easy and transparent, check out GLib's GModule API.
这篇关于在C或C实现插件系统++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!