gfactory
Loading...
Searching...
No Matches
DynamicLib Struct Reference

Helper that loads a shared library and holds its POSIX handle. More...

#include <gdl.h>

Public Member Functions

 DynamicLib ()=default
 Default constructor (does not load anything).
 
 DynamicLib (std::shared_ptr< GLogger > logger, std::string path)
 Construct and attempt to load a dynamic library.
 
 ~DynamicLib ()
 Destructor closes the library handle (if loaded).
 

Data Fields

dlhandle handle = nullptr
 POSIX handle of the dynamic library.
 

Detailed Description

This structure centralizes:

  • file discovery (try user path, then GEMC install lib/, then build/ for test runs),
  • opening the library using dlopen, and
  • closing the library using dlclose in the destructor.

Search strategy

Given a library name or path:

  1. Try the provided value as-is.
  2. If not found, try ${GEMC_ROOT}/lib/<name>.
  3. If still not found, try ${GEMC_ROOT}/build/<name> (useful for Meson tests in the build tree).

Error reporting

Errors are reported via the configured GLogger instance using:

  • ERR_DLNOTFOUND when no file is found, and
  • ERR_DLHANDLENOTFOUND when the file exists but dlopen returns null (with dlerror text).

Definition at line 50 of file gdl.h.

Constructor & Destructor Documentation

◆ DynamicLib() [1/2]

DynamicLib::DynamicLib ( )
default

◆ DynamicLib() [2/2]

DynamicLib::DynamicLib ( std::shared_ptr< GLogger > logger,
std::string path )
inline
Parameters
loggerLogger used for messages and errors.
pathLibrary filename or path (e.g., myplugin.gplugin).

The constructor attempts multiple locations (see class description) and, if found, opens the library via load_lib().

Definition at line 82 of file gdl.h.

◆ ~DynamicLib()

DynamicLib::~DynamicLib ( )
inline
Note
dlclose is called only if handle is not null.

Definition at line 130 of file gdl.h.

Field Documentation

◆ handle

dlhandle DynamicLib::handle = nullptr

This is the value returned by dlopen and is later consumed by dlsym.

Definition at line 123 of file gdl.h.


The documentation for this struct was generated from the following file: