...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::dll::experimental::import_mangled
// In header: <boost/dll/import_mangled.hpp> template<class ... Args> result_type import_mangled(const boost::dll::fs::path & lib, const char * name, load_mode::type mode = load_mode::default_mode); template<class ... Args> result_type import_mangled(const boost::dll::fs::path & lib, const std::string & name, load_mode::type mode = load_mode::default_mode); template<class ... Args> result_type import_mangled(const smart_library & lib, const char * name); template<class ... Args> result_type import_mangled(const smart_library & lib, const std::string & name); template<class ... Args> result_type import_mangled(smart_library && lib, const char * name); template<class ... Args> result_type import_mangled(smart_library && lib, const std::string & name); template<class ... Args> result_type import_mangled(const shared_library & lib, const char * name); template<class ... Args> result_type import_mangled(const shared_library & lib, const std::string & name); template<class ... Args> result_type import_mangled(shared_library && lib, const char * name); template<class ... Args> result_type import_mangled(shared_library && lib, const std::string & name);
Returns callable object or boost::shared_ptr<T> that holds the symbol imported from the loaded library. Returned value refcounts usage of the loaded shared library, so that it won't get unload until all copies of return value are not destroyed.
For importing symbols by alias names use boost::dll::import_alias method.
Examples:
boost::function<int(int)> f = import_mangled<int(int)>("test_lib.so", "integer_func_name"); auto f_cpp11 = import_mangled<int(int)>("test_lib.so", "integer_func_name");
boost::shared_ptr<int> i = import_mangled<int>("test_lib.so", "integer_name");
Additionally you can also import overloaded symbols, including member-functions.
auto fp = import_mangled<void(int), void(double)>("test_lib.so", "func");
auto fp = import_mangled<my_class, void(int), void(double)>("test_lib.so", "func");
If qualified member-functions are needed, this can be set by repeating the class name with const or volatile. All following signatures after the redifintion will use this, i.e. the latest.
*
auto fp = import_mangled<my_class, void(int), void(double), const my_class, void(int), void(double)>("test_lib.so", "func");
Template parameter T: Type of the symbol that we are going to import. Must be explicitly specified.
Parameters: |
|
||||||
Returns: |
callable object if T is a function type, or boost::shared_ptr<T> if T is an object type. |
||||||
Throws: |