简体   繁体   中英

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.

Edit : I found this Dr Dobbs Post from 2007; 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.

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.

Qt has a nice plugin system . 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

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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