Mercurial > code
view C++/doc/Dynlib/Home.md @ 334:0b576ee64d45
* Create brand new hierarchy
* Rename DynLib to Dynlib
* Remove some warnings
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 08 Mar 2015 14:26:33 +0100 |
parents | |
children |
line wrap: on
line source
# DynLib This class provides routines to load shared libraries in a portable manner. ## Operating system support | System | Support | Remarks | |---------|----------|-------------------------------------| | Linux | Complete | Linker needs -ldl linker flags | | FreeBSD | Complete | | | Windows | Complete | Immediately policy is not available | ## API Reference ### Macros constants - [DYNLIB_EXPORT](macro/DYNLIB_EXPORT.md) ### Classes - [DynLib](class/Dynlib.md) ## Tutorial This is the library code to be compiled as a shared module. **Library.cpp** ````cpp #include <iostream> #include <string> #include "DynLib.h" extern "C" { DYNLIB_EXPORT void a_sayHello(const std::string &name) { std::cout << "Hello " << name << "!" << std::endl; } } ```` And this is the code that load the shared module. **Main.cpp** ````cpp #include <iostream> #include "DynLib.h" using HelloFunc = void (*)(const std::string &); int main(void) { try { DynLib library("./liba.so"); HelloFunc hello = library.sym<HelloFunc>("a_sayHello"); hello("Test"); } catch (const std::exception &error) { std::cerr << error.what() << std::endl; } return 0; } ````