| 1 | // main.cc
|
|---|
| 2 |
|
|---|
| 3 | #include <dlfcn.h>
|
|---|
| 4 | #include <iostream>
|
|---|
| 5 |
|
|---|
| 6 | #include <boost/thread/tss.hpp>
|
|---|
| 7 |
|
|---|
| 8 | namespace {
|
|---|
| 9 | class global_type { };
|
|---|
| 10 |
|
|---|
| 11 | void die() {
|
|---|
| 12 | std::cerr << dlerror() << std::endl;
|
|---|
| 13 | exit(1);
|
|---|
| 14 | }
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | int main() {
|
|---|
| 18 | boost::thread_specific_ptr< global_type > global_tss;
|
|---|
| 19 |
|
|---|
| 20 | void *handle = dlopen("./plugin.so", RTLD_LAZY | RTLD_LOCAL);
|
|---|
| 21 | if (!handle) die();
|
|---|
| 22 |
|
|---|
| 23 | void *ptr = dlsym(handle, "run_plugin");
|
|---|
| 24 | if (!ptr) die();
|
|---|
| 25 |
|
|---|
| 26 | typedef void (*fptr_t) ();
|
|---|
| 27 | fptr_t fptr = (fptr_t) ptr;
|
|---|
| 28 |
|
|---|
| 29 | (*fptr) ();
|
|---|
| 30 |
|
|---|
| 31 | if (dlclose(handle)) die();
|
|---|
| 32 |
|
|---|
| 33 | return 0;
|
|---|
| 34 | }
|
|---|