A simple, multi-platform dynamic loader written in C++20.
- C++20 compiler and standard library.
- CMake 3.22+.
Link to the dino::dino
target in CMake.
#include <dino/library.hpp> // 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<int(char)>("foobar");
// use library.load_ptr() to get a function pointer instead.
std::cout << func('x'); // call function and print returned int.
DINO_BUILD_TESTS
: SetON
to build tests (OFF
by default unlessdino
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.
Unfortunately not, both dlsym()
and GetProcAddress()
operate on symbol names only.
Undefined behaviour.
Contributions are welcome.