An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# dino

**A simple, multi-platform dynamic loader written in C++20.**

[![Build status](https://github.com/karnkaul/dino/actions/workflows/ci.yml/badge.svg)](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)