Dynamic selection of static lib to extend class?
-
I'm looking for best practices to accomplish an application that loads compiled "programs" based on a config file, hopefully as a static lib. The main app, loads config.json, parses it which includes a name of a "program". I'd like to have a class Program.cpp that is extended by any one of a number of "programs" that override/implement key functions of how that program performs.
I believe the way to do this, but wanting to get feedback on the method first, is to have the main program:
main.cpp
Program.cpp
config.json {"program": "MailManager"}The compiled executable would be on the server, alongside with the following static libraries:
MailManager.cpp compiled to programs/MailManager.so
MailManager_strict.cpp compiled to programs/MailManger_strict.soThe use case is to be able to, shutdown the main app, modify config.json to use any one of many pre-comiled "programs", and then restart the main app, whereas it'll load a different static library to extend Program based on the config file.
Thanks for any feedback!
-
I'm looking for best practices to accomplish an application that loads compiled "programs" based on a config file, hopefully as a static lib. The main app, loads config.json, parses it which includes a name of a "program". I'd like to have a class Program.cpp that is extended by any one of a number of "programs" that override/implement key functions of how that program performs.
I believe the way to do this, but wanting to get feedback on the method first, is to have the main program:
main.cpp
Program.cpp
config.json {"program": "MailManager"}The compiled executable would be on the server, alongside with the following static libraries:
MailManager.cpp compiled to programs/MailManager.so
MailManager_strict.cpp compiled to programs/MailManger_strict.soThe use case is to be able to, shutdown the main app, modify config.json to use any one of many pre-comiled "programs", and then restart the main app, whereas it'll load a different static library to extend Program based on the config file.
Thanks for any feedback!
@apampe Why static libraries? Static libraries are used during linking of your app and are part of your app executable after linking.
.so are shared libraries not static (static libs have .a extension on Linux).
What you want to do sounds a lot like plug-ins. Take a look at http://doc.qt.io/qt-5/plugins-howto.html
Or just create shared libraries (without main!) and load them dynamically using dlopen (but it is easier to use Qt plug-ins).