简体   繁体   English

跨平台C ++动态库插件加载器

[英]Cross-Platform C++ Dynamic Library Plugin Loader

I was just wondering what my options were for cross-platform implementations for the dynamic loading of plugins using shared libraries. 我只是想知道我对使用共享库动态加载插件的跨平台实现的选择。 So far the only one that I have found is: 到目前为止,我发现的唯一一个是:

And I was just wondering if I had other options? 而我只是想知道我是否有其他选择? Essentially, I want to be able to put plugins in shared object files, and load them at runtime and I wanted to do it in a cross-platform C++ way. 本质上,我希望能够将插件放在共享对象文件中,并在运行时加载它们,我希望以跨平台的C ++方式实现。

Edit : I found this Dr Dobbs Post from 2007; 编辑 :我从2007年找到了Dobbs博士的这篇博士 ; surely somebody has come up with something more since then. 从那以后,肯定有人提出了更多的东西。

You could look into Boost Extension, though it has not yet been accepted into Boost. 您可以查看Boost Extension,但尚未被Boost接受。

The Boost.Extension library has been developed to ease the development of plugins and similar extensions to software using shared libraries. Boost.Extension库的开发旨在简化使用共享库的插件和类似软件扩展的开发。 Classes, functions and data can be made available from shared libraries and loaded by the application. 可以从共享库中获取类,函数和数据,并由应用程序加载。

Qt has a nice plugin system . Qt有一个很好的插件系统 You should take a look at the second part of that page. 您应该看一下该页面的第二部分

If you want something simple and lightweight try: https://pocoproject.org/docs/package-Foundation.SharedLibrary.html 如果你想要简单轻巧的东西,请尝试: https//pocoproject.org/docs/package-Foundation.SharedLibrary.html

Using the SharedLibrary class it takes three lines to call a function in a C shared library: 使用SharedLibrary类需要三行来调用C共享库中的函数:

Poco::SharedLibrary lib("libfoo.so");
int (* foo)(int) = reinterpret_cast<int (*)(int)>(lib.getSymbol("foo"));    
printf("answer %d\n", foo(5));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM