#include <dlfcn.h>
#include <cstdio>
#include <cstdlib>

void ls()
{
	printf("ls: %d\n", ::system("ls"));
}

static void* libHandle;

void load()
{
	ls();
	libHandle = dlopen("./libfoo.so", RTLD_NOW | RTLD_LOCAL);
	printf("libhandle: %p\n", libHandle);
	ls();
}

void init()
{
	ls();
	using F = int (*)();
	auto rawf = dlsym(libHandle, "f");
	printf("rawf: %p\n", rawf);
	F f = reinterpret_cast<F>(rawf);
	ls();
	printf("f(): %d\n", f());
	ls();
}

void unload()
{
	ls();
	dlclose(libHandle);
	ls();
}

