Releases: abin-z/DynamicLibLoader
Releases · abin-z/DynamicLibLoader
v0.9.7
DynamicLibLoader v0.9.7
dynamic_library.hpp is a single-file header-only library for loading dynamic libraries across platforms.
Highlights
- Single-File Header-Only: Just include
dynamic_library.hpp— no other dependencies. - Optimized & Modern C++: Refactored for clarity, safety, and efficiency. Uses RAII, move semantics, type traits, mutexes, and unordered maps. Symbol caching (
invoke()) minimizes repeated lookups. - Cross-Platform: Windows (.dll), Linux (.so), macOS (.dylib)
- RAII Resource Management: Automatically loads/unloads dynamic libraries.
- Error Handling: Throws
std::runtime_errorwith detailed platform-specific error messages. - Cached & Uncached Symbol Access:
invoke()caches symbols for efficiency;invoke_uncached()avoids caching.
Usage Example
#include "dynamic_library.hpp"
dll::dynamic_library lib("mylib.dll"); // or .so / .dylib
auto func = lib.get<int(int,int)>("my_function");
int result = func(1, 2);
// Cached invocation
int cached_result = lib.invoke<int(int,int)>("my_function", 3, 4);DynamicLibLoader v0.9.7
dynamic_library.hpp 是一个 单文件 Header-Only 库,用于跨平台加载动态库。
主要特点
- 单文件 Header-Only: 只需包含
dynamic_library.hpp,无需任何额外依赖。 - 优化 & 现代 C++: 使用 C++11+ 写法重构,提升可读性、性能与安全性。使用 RAII、移动语义、类型特性、互斥锁和无序映射。符号缓存 (
invoke()) 减少重复查找,提高调用效率。 - 跨平台支持: Windows (.dll)、Linux (.so)、macOS (.dylib)
- RAII 资源管理: 自动加载/卸载动态库,确保资源安全释放。
- 错误处理: 抛出
std::runtime_error并附带平台相关详细错误信息。 - 符号访问:
invoke()会缓存符号以提升效率;invoke_uncached()不缓存符号。
使用示例
#include "dynamic_library.hpp"
dll::dynamic_library lib("mylib.dll"); // 或 .so / .dylib
auto func = lib.get<int(int,int)>("my_function");
int result = func(1, 2);
// 使用缓存调用
int cached_result = lib.invoke<int(int,int)>("my_function", 3, 4);v0.9.5
Release version 0.9.5
New Features:
- Added
has_symbolfunction to determine whether a symbol exists - Added
get_variablefunction to get variables in a dynamic library, and throws an exception if the variable does not exist - Added
try_get_variablefunction to get variables in a dynamic library, and returns nullptr if the variable does not exist - Supports default construction, added
loadfunction to support delayed loading of dynamic libraries
新功能:
- 新增
has_symbol函数, 用于判断符号是否存在 - 新增
get_variable函数, 用于获取动态库中的变量, 变量不存在抛异常 - 新增
try_get_variable函数, 用于获取动态库的变量, 变量不存在返回nullptr - 支持默认构造, 新增
load函数, 支持延迟加载动态库
Key Features:
- Cross-platform support: Compatible with Windows and POSIX (Linux/macOS).
- RAII Resource Management: Loads the library on construction and unloads it on destruction.
- Error Handling: Throws detailed std::runtime_error exceptions with platform-specific error messages when failing to load the library or symbols.
- Symbol Caching: invoke() supports symbol caching for improved efficiency.
- Cached and Uncached Interfaces: Use invoke() (cached) or invoke_uncached() (non-cached).
- No Dependencies: Relies solely on the standard library.
主要特性:
- 跨平台支持:兼容 Windows 和 POSIX(Linux/macOS)。
- RAII 资源管理:在构造时加载库,并在析构时卸载。
- 错误处理:当加载库或符号失败时,抛出详细的 std::runtime_error 异常,并附带平台特定的错误消息。
- 符号缓存:invoke() 支持符号缓存,以提高效率。
- 缓存和非缓存接口:使用 invoke()(缓存)或 invoke_uncached()(非缓存)。
- 无依赖:仅依赖于标准库。
v0.9.2
Release version 0.9.2
Key Features:
- Cross-platform support: Compatible with Windows and POSIX (Linux/macOS).
- RAII Resource Management: Loads the library on construction and unloads it on destruction.
- Error Handling: Throws detailed
std::runtime_errorexceptions with platform-specific error messages when failing to load the library or symbols. - Symbol Caching:
invoke()supports symbol caching for improved efficiency. - Cached and Uncached Interfaces: Use
invoke()(cached) orinvoke_uncached()(non-cached). - No Dependencies: Relies solely on the standard library.
主要特性:
- 跨平台支持:兼容 Windows 和 POSIX(Linux/macOS)。
- RAII 资源管理:在构造时加载库,并在析构时卸载。
- 错误处理:当加载库或符号失败时,抛出详细的
std::runtime_error异常,并附带平台特定的错误消息。 - 符号缓存:
invoke()支持符号缓存,以提高效率。 - 缓存和非缓存接口:使用
invoke()(缓存)或invoke_uncached()(非缓存)。 - 无依赖:仅依赖于标准库。