#include <iostream>
#include <dlfcn.h>

using namespace std;

void *DLOpenOrDie(const string& path) {
    const auto lib = dlopen(path.c_str(), RTLD_LAZY);
    if (!lib) {
        cerr << "Could not load library: " << dlerror() << endl;
    }
    return lib;
}

void *DLSymOrDie(void *lib, const string& func_name) {
    const auto func = dlsym(lib, func_name.c_str());
    const auto dlsym_error = dlerror();
    if (dlsym_error) {
        cerr << "Could not load symbol: " << dlsym_error << endl;
        dlclose(lib);
        exit(EXIT_FAILURE);
    }
    return func;
}

