9

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.

Edit: I found this Dr Dobbs Post from 2007; surely somebody has come up with something more since then.

Robert Massaioli
  • 13,379
  • 7
  • 57
  • 73

3 Answers3

7

You could look into Boost Extension, though it has not yet been accepted into Boost.

The Boost.Extension library has been developed to ease the development of plugins and similar extensions to software using shared libraries. Classes, functions and data can be made available from shared libraries and loaded by the application.

Sam Miller
  • 23,808
  • 4
  • 67
  • 87
  • Nice. I love the Boost Libraries, I'll see how close this is to becoming apart of boost proper. – Robert Massaioli Oct 20 '10 at 13:41
  • 2
    Don't do this. The original author has deprecated his own work. http://blog.redshoelace.com/2014/01/c0x.html#links – johnwbyrd Apr 16 '14 at 01:50
  • Since 2016, Boost v1.61.0 has added dll. [Reference](https://www.boost.org/users/history/). [Documentation](https://www.boost.org/doc/libs/1_73_0/doc/html/boost_dll.html) for 1.73.0 – Louis Go Aug 05 '20 at 05:24
3

Qt has a nice plugin system. You should take a look at the second part of that page.

mtvec
  • 17,846
  • 5
  • 52
  • 83
1

If you want something simple and lightweight try: 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:

Poco::SharedLibrary lib("libfoo.so");
int (* foo)(int) = reinterpret_cast<int (*)(int)>(lib.getSymbol("foo"));    
printf("answer %d\n", foo(5));
Machta
  • 1,656
  • 2
  • 16
  • 28