Ticket #8414: test_case

File test_case, 1.1 KB (added by charles quarra <charlls_quarra@…>, 10 years ago)
Line 
1
2
3
4
5g++ main.cpp -o xmain -ldl
6
7main.cpp:
8#include <dlfcn.h>
9#include <iostream>
10int
11main()
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
24g++ -I/path/to/boost/includes -fPIC -shared -rdynamic test_plugin.cpp -o libpluginTest.so -L/path/to/boost/libs -lrt
25
26test_plugin.cpp:
27#include <iostream>
28#include <boost/flyweight.hpp>
29
30typedef boost::flyweight< std::string > SymbolName_t;
31
32SymbolName_t getEmptyStringSymbol() {
33 SymbolName_t empty("");
34 return empty;
35 }
36
37
38
39void __attribute__ ((constructor)) library_init()
40{
41 std::cout << "Library constructor: " << std::endl;
42}
43void __attribute__ ((destructor)) library_fini()
44{
45 std::cout << "Library destructor:" << std::endl;
46}
47
48
49tested on:
50g++-4.6 (Ubuntu/Linaro 4.6.3-10ubuntu1) 4.6.3 20120918 (prerelease)
51g++-4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2