https://github.com/karnkaul/dino
C++20 Library for dynamically loading shared libraries and functions.
https://github.com/karnkaul/dino
cpp cpp20 cpp20-library dynamic-loading loader
Last synced: 11 months ago
JSON representation
C++20 Library for dynamically loading shared libraries and functions.
- Host: GitHub
- URL: https://github.com/karnkaul/dino
- Owner: karnkaul
- License: mit
- Created: 2021-06-23T04:31:12.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-18T15:01:54.000Z (almost 2 years ago)
- Last Synced: 2025-03-25T16:55:35.372Z (11 months ago)
- Topics: cpp, cpp20, cpp20-library, dynamic-loading, loader
- Language: C++
- Homepage:
- Size: 39.1 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dino
**A simple, multi-platform dynamic loader written in C++20.**
[](https://github.com/karnkaul/dino/actions/workflows/ci.yml)
## Requirements
- C++20 compiler and standard library.
- CMake 3.22+.
## Usage
Link to the `dino::dino` target in CMake.
```cpp
#include // include the header.
// ...
auto const path = dino::Location{
.identifier = "lib-name", // platform-agnostic identifier of library
// (for libfoo.so/foo.dll the id is foo).
.directory = "./" // directory to use; leave empty to
// rely on the default search order.
}.to_path(); // build a path using the default
// Affix for this platform.
// load the library.
auto const library = dino::Library{path};
// use dino::Library::make(path) to avoid exceptions on failure.
// load a function reference.
// the signature must match what's in the library source!
// otherwise, calling the function invokes undefined behavior.
auto const func = library.load("foobar");
// use library.load_ptr() to get a function pointer instead.
std::cout << func('x'); // call function and print returned int.
```
### CMake build options
- `DINO_BUILD_TESTS`: Set `ON` to build tests (`OFF` by default unless `dino` is the project root)
- `DINO_BACKEND`: Set to 'unix' or 'windows' to force a particular backend. Default value is 'default' which uses the host platform as detected by CMake.
## FAQ
### Are the loaded functions actually type-safe?
Unfortunately not, both `dlsym()` and `GetProcAddress()` operate on symbol names only.
### What happens if the names match but signatures don't?
Undefined behaviour.
## Contributing
Contributions are welcome.
[Original repository](https://github.com/karnkaul/dino)
[LICENCE](LICENSE)