g++ main.cpp -o xmain -ldl main.cpp: #include #include int main() { std::cout << "load: " << std::endl; void *foo = dlopen("./libpluginTest.so", RTLD_NOW); std::cout << "load: library loaded "<< foo << std::endl; if (dlclose(foo) < 0) { std::cout << "load: library close failed " << std::endl; return 1; } std::cout << "load: library closed " << std::endl; return 0; } g++ -I/path/to/boost/includes -fPIC -shared -rdynamic test_plugin.cpp -o libpluginTest.so -L/path/to/boost/libs -lrt test_plugin.cpp: #include #include typedef boost::flyweight< std::string > SymbolName_t; SymbolName_t getEmptyStringSymbol() { SymbolName_t empty(""); return empty; } void __attribute__ ((constructor)) library_init() { std::cout << "Library constructor: " << std::endl; } void __attribute__ ((destructor)) library_fini() { std::cout << "Library destructor:" << std::endl; } tested on: g++-4.6 (Ubuntu/Linaro 4.6.3-10ubuntu1) 4.6.3 20120918 (prerelease) g++-4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2