Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the simplest way to write portable dynamically loadable libraries in C++?

I'm working on a project which has multiple similar code paths which I'd like to separate from the main project into plugins. The project must remain cross-platform compatible, and all of the dynamic library loading APIs I've looked into are platform specific.

What's the simplest way to create a dynamic library loading system which can be compiled and run on multiple operating systems without extra modification of the code? Ideally, I'd like to write one plugin, and have it work on all the operating systems the project supports.

Thanks.

like image 442
jakogut Avatar asked Aug 24 '10 21:08

jakogut


2 Answers

You will have to use platform dependent code for the loading system. It's different loading a DLL on Windows than loading a shared object in Unix. But, with a couple of #ifdef you will be able to have mostly the same code base in the loader.

Having said that, I think you can make your plugins platform independent. Of course, you will have to compile it for every platform, but the code will be 99% the same.

like image 133
Pablo Santa Cruz Avatar answered Oct 05 '22 20:10

Pablo Santa Cruz


Dynamic library loading an Windows and Unix/Linux works with 3 functions. A pair of functions to load/unload the libraries, and another function to get the address of a function in the library. You can easily write a wrapper around these three functions to provide cross operating systems suppport.

like image 21
Didier Trosset Avatar answered Oct 05 '22 21:10

Didier Trosset