-
OS-Specific API Wrapper: Simplifies the process of loading shared objects by providing a unified interface across different operating systems.
-
Standardized Module Definition: The included header file enables developers to define modules using macros, ensuring consistency and ease of use.
-
Cross-Platform Compatibility: Works seamlessly across various operating systems, allowing developers to write code without worrying about platform-specific nuances.
An example is provided in "./examples"
-
Include Header: Include the
<dyn_module.hpp>
header file to access macro definitions. -
Define Module Header: Define a header for your module, outlining the signature of the functions that need to be exported to the application. Create a "module" structure containing function pointers corresponding to the defined function signatures.
-
Include Module Header: Include the header file of your module.
-
Implement Functions: Implement the necessary functions required by your module.
-
Create Global Variable: Create a global variable named
module
with function pointers pointing to the functions you've implemented and need to export. You can include "private" functions within the module that are not included in the module definition.
IMPORTANT: External modules should, by default, be compiled with the -fvisibility=hidden flag (or its equivalent). This flag prevents symbols from being exported from the object file, reducing the risk of name conflicts—an issue that can be challenging to debug. Only the Module itself is exported, and this is achieved via a specific macro.
An example is provided to demonstrate the usage. From the application's perspective (Loader):
-
Include Dynamic Library Loader Header: Include
"dynlib.hpp"
. -
Include Library Header: Include the common header for your library.
-
Provide Object Path: Provide the path of the
.so
(or.dll
) object to import, where the definitions are located. -
Retrieve Imported Module: Retrieve the imported module.
Note: If the module's name isn't specified, it is assumed that the external library developer followed the naming conventions given in the header. If not, you can use a custom module name and type name to define the structure manually.
This project is licensed under the MIT License, allowing for unrestricted use, modification, and distribution. Please review the LICENSE file for detailed licensing terms.