summaryrefslogtreecommitdiff
path: root/slicer/test/helpers.cpp
blob: 5527f5aaebd9ff284a66529c5e52a8c67ee9ed1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "helpers.h"
#include <stdexcept>
#include <stdlib.h>
#include <dlfcn.h>

void
system(const std::string & cmd)
{
	if (system(cmd.c_str())) {
		fprintf(stderr, "Failed to execute:\n\t%s\n", cmd.c_str());
		throw std::runtime_error(cmd);
	}
}

void *
loadlib(const boost::filesystem::path & so)
{
	auto handle = dlopen(so.string().c_str(), RTLD_NOW | RTLD_GLOBAL);
	if (!handle) {
		throw std::runtime_error(dlerror());
	}
	return handle;
}

void
closelib(void * handle)
{
	if (dlclose(handle)) {
		throw std::runtime_error(dlerror());
	}
}