17void*
open(
const char* file) {
19 if (HMODULE handle = LoadLibraryA(file)) {
20 return static_cast<void*
>(handle);
22 error(
"could not load plugin '{}' due to error '{}'\n"
23 "see https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes\n",
24 file, GetLastError());
27 if (
void* handle = dlopen(file, RTLD_NOW))
29 else if (
auto err = dlerror())
30 error(
"could not load plugin '{}' due to error '{}'\n", file, err);
32 error(
"could not load plugin '{}'\n", file);
36void*
get(
void* handle,
const char* symbol) {
38 if (
auto addr = GetProcAddress(
static_cast<HMODULE
>(handle), symbol)) {
39 return reinterpret_cast<void*
>(addr);
41 error(
"could not find symbol '{}' in plugin due to error '{}'\n"
42 "see (https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes)\n",
43 symbol, GetLastError());
47 void* addr = dlsym(handle, symbol);
48 if (
auto err = dlerror())
49 error(
"could not find symbol '{}' in plugin due to error '{}' \n", symbol, err);
57 if (!FreeLibrary(
static_cast<HMODULE
>(handle)))
error(
"FreeLibrary() failed\n");
59 if (
auto err = dlclose(handle))
error(
"dlclose() failed with error code '{}'\n", err);
void * get(void *handle, const char *symbol_name)
void * open(const char *filename)
void error(Loc loc, const char *f, Args &&... args)