In the latest part of Programming modular applications in C++ I have shown you some practical examples of modular applications. These applications probably work well with your dedicated plugins. Problems begin when you try to mix in plugins written by your users which have been compiled using different compilers (it might work) or even operating systems (it cannot work!).
When it comes to real applications we can use this approach very rarely. We are
guaranteed that dynamically linked shared libraries as plugins will work as they
are expected only when we will compile them using the same version of compiler
and operating system which we have used to produce application's binary file.
Second restriction of approach which I have presented in last two articles
(introduction and part 1) is that these programs work only on some systems
compatibile with UNIX. When we need portable modular application we should take
into account using dedicated library which provides portable interface. An
example of such library is
Poco::SharedLibrary. I'm going to write
something about it later.
Any good solution?
Problems with C++ plugins
I told you that C++ plugins may cause problems when we use different compilers to convert source code into binary files. Main cause of this problem are differences in Application Binary Interface which may be different in the same source code compiled by different compilers or even different versions of the same compiler. This problem is noticable in UNIX-like operating systems. Often used format called Executable and Linkable Format (ELF) becomes more and more popular what may result in better compatibility between applications compiled used different compilers which will use it by default. However there is always a risk that somebody will compile plugin with different compiler and ABI will be other than in application. And what if one day you decide that you will release your application for new operating system? New version will not be able to use plugins compiled for other os'. You will have to ask developers to compile their plugins for new platform. It may be difficult or even impossible.
The number of problems is less in case of open source software. When you release new version you just get source code of all plugins and compile them for new environment. It is easier but sometimes may be hard to do if there are thousands of plugins.
Really portable plugins
Java instead of C++?
What if plugins are not something exotic in your program but they are implemented as big parts of application with full rights? Maybe it is good reason why you should resign from C++ and use one of languages which has their own layer between 'executable code' and operating system. I mean Java and Python. This way is used by Eclipse. Eclipse is a platform written in Java. Bare Eclipse is useless. Its main functionalities are provided by plugins. If you want to write in C++, you use Eclipse CDT, for PHP you have Eclipse with different set of plugins. Last time I have seen Eclipse Arduino IDE. Eclipse can be run of every system which has its implementation of Java virtual machine.
In my opinion, better language is Python. It's also available on different platforms, but it is much faster. What's more you can compile its code to Java executable code (with Jython) which can be run on systems which has Java but has not Python (e.g. old mobile devices).