Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good patterns for a C/C++ plugin-based system?

Tags:

c++

c

plugins

When developing a C/C++ (=2?) plugin based framework with shared objects/dynamic libraries that need to support live swapping what examples would be helpful to look at for implementation details?

Thanks.

Note: live swapping is the key point here, no need to restart the system is a requirement

like image 744
Robert Gould Avatar asked Apr 24 '09 11:04

Robert Gould


3 Answers

If you are on POSIX, dlopen(), dlsym() and dlclose() are all you need.

See man dlsym for details and examples.

There is a good article about loading dynamic libraries, and plugin infrastructure is an example.

EDIT OP added Windows as requirement so this approach won't help since Windows isn't POSIX-compliant. However there are similar functions in WinAPI - see here.

like image 53
qrdl Avatar answered Nov 03 '22 02:11

qrdl


You might want to try Boost.Extension but beware : despite its name, it is not one of boost libraries.

Here is a link to its documentation.

like image 4
Benoît Avatar answered Nov 03 '22 02:11

Benoît


For C++ plugins you can check this article which detail how to achieve it with the previously mentionned posix calls.

Quoting the article :

Given that we can use these functions to access functions in a C library, how do we use them to access classes in a C++ library? There are several problems to overcome. One is that we must be able to locate the symbols we need in the library. This is trickier than it might seem because of the difference between the way symbols are stored in C and C++ files.

like image 4
fa. Avatar answered Nov 03 '22 02:11

fa.