Base module

SharedLibrary

Loads a shared library at runtime and resolves exported symbols.

SharedLibrary

#include <icy/sharedlibrary.h>

Loads a shared library at runtime and resolves exported symbols.

Public Methods

ReturnNameDescription
boolopen inlineOpens a shared library. The filename is in utf-8. Returns true on success and false on error. Call [SharedLibrary::error()](#error-7) to get the error message.
voidclose inlineCloses the shared library.
boolsym inlineRetrieves a data pointer from a dynamic library. It is legal for a symbol to map to nullptr. Returns 0 on success and -1 if the symbol was not found.
voidsetError inlineReads the last libuv dynamic-linker error, stores it in _error, and throws a std::runtime_error with the combined prefix and error message.
std::stringerror const inlineReturns the last error message recorded by setError(). Empty if no error has occurred.

open

inline

inline bool open(const std::string & path)

Opens a shared library. The filename is in utf-8. Returns true on success and false on error. Call [SharedLibrary::error()](#error-7) to get the error message.


close

inline

inline void close()

Closes the shared library.


sym

inline

inline bool sym(const char * name, void ** ptr)

Retrieves a data pointer from a dynamic library. It is legal for a symbol to map to nullptr. Returns 0 on success and -1 if the symbol was not found.


setError

inline

inline void setError(const std::string & prefix)

Reads the last libuv dynamic-linker error, stores it in _error, and throws a std::runtime_error with the combined prefix and error message.

Parameters

  • prefix Human-readable context string prepended to the error detail.

Exceptions

  • std::runtime_error always.

error

const inline

inline std::string error() const

Returns the last error message recorded by setError(). Empty if no error has occurred.

Returns

Last error string.

Protected Attributes

ReturnNameDescription
uv_lib_t_lib
std::string_error

_lib

uv_lib_t _lib

_error

std::string _error