1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 | g++ main.cpp -o xmain -ldl
|
---|
6 |
|
---|
7 | main.cpp:
|
---|
8 | #include <dlfcn.h>
|
---|
9 | #include <iostream>
|
---|
10 | int
|
---|
11 | main()
|
---|
12 | {
|
---|
13 | std::cout << "load: " << std::endl;
|
---|
14 | void *foo = dlopen("./libpluginTest.so", RTLD_NOW);
|
---|
15 | std::cout << "load: library loaded "<< foo << std::endl;
|
---|
16 | if (dlclose(foo) < 0) {
|
---|
17 | std::cout << "load: library close failed " << std::endl;
|
---|
18 | return 1;
|
---|
19 | }
|
---|
20 | std::cout << "load: library closed " << std::endl;
|
---|
21 | return 0;
|
---|
22 | }
|
---|
23 |
|
---|
24 | g++ -I/path/to/boost/includes -fPIC -shared -rdynamic test_plugin.cpp -o libpluginTest.so -L/path/to/boost/libs -lrt
|
---|
25 |
|
---|
26 | test_plugin.cpp:
|
---|
27 | #include <iostream>
|
---|
28 | #include <boost/flyweight.hpp>
|
---|
29 |
|
---|
30 | typedef boost::flyweight< std::string > SymbolName_t;
|
---|
31 |
|
---|
32 | SymbolName_t getEmptyStringSymbol() {
|
---|
33 | SymbolName_t empty("");
|
---|
34 | return empty;
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 | void __attribute__ ((constructor)) library_init()
|
---|
40 | {
|
---|
41 | std::cout << "Library constructor: " << std::endl;
|
---|
42 | }
|
---|
43 | void __attribute__ ((destructor)) library_fini()
|
---|
44 | {
|
---|
45 | std::cout << "Library destructor:" << std::endl;
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | tested on:
|
---|
50 | g++-4.6 (Ubuntu/Linaro 4.6.3-10ubuntu1) 4.6.3 20120918 (prerelease)
|
---|
51 | g++-4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
|
---|