Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the master branch, built from commit 25d613dfbc.
PrevUpHomeNext

Function import_symbol

boost::dll::import_symbol

Synopsis

// In header: <boost/dll/import.hpp>


template<typename T> 
  result_type import_symbol(const boost::dll::fs::path & lib, 
                            const char * name, 
                            load_mode::type mode = load_mode::default_mode);
template<typename T> 
  result_type import_symbol(const boost::dll::fs::path & lib, 
                            const std::string & name, 
                            load_mode::type mode = load_mode::default_mode);
template<typename T> 
  result_type import_symbol(const shared_library & lib, const char * name);
template<typename T> 
  result_type import_symbol(const shared_library & lib, 
                            const std::string & name);
template<typename T> 
  result_type import_symbol(shared_library && lib, const char * name);
template<typename T> 
  result_type import_symbol(shared_library && lib, const std::string & name);

Description

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.

This call will succeed if call to boost::dll::shared_library::has(const char* ) function with the same symbol name returned true.

For importing symbols by alias names use boost::dll::import_alias method.

Examples:

boost::function<int(int)> f = import_symbol<int(int)>("test_lib.so", "integer_func_name");

auto f_cpp11 = import_symbol<int(int)>("test_lib.so", "integer_func_name");
boost::shared_ptr<int> i = import_symbol<int>("test_lib.so", "integer_name");

Template parameter T: Type of the symbol that we are going to import. Must be explicitly specified.

Parameters:

lib

Path to shared library or shared library to load function from.

mode

An mode that will be used on library load.

name

Null-terminated C or C++ mangled name of the function to import. Can handle std::string, char*, const char*.

Returns:

callable object if T is a function type, or boost::shared_ptr<T> if T is an object type.

Throws:


PrevUpHomeNext