A class for handling shared libraries (DLLs, SO, DyLibs). More...
#include <Library.h>
Public Member Functions | |
void * | getAddress (const char *symbol) const |
Return the address where the given symbol is loaded into memory. More... | |
const std::string & | getFileName () const |
Return the shared library file name as informed in the constructor. More... | |
bool | isLoaded () const |
Return true if the shared library is loaded otherwise return false. More... | |
Library (const std::string &slib_file_name, const bool &delay_load=false) | |
Load a new shared library. More... | |
void | load () |
Load the shared library to memory. More... | |
void | unload () |
Force the unload of the shared library from memory. More... | |
~Library () | |
The destructor automatically unloads from memory the shared library if it was not unloaded explicitly. More... | |
Static Public Member Functions | |
static void | addSearchDir (const std::string &dir_name) |
Add the informed dir to the path used by the operational system to lookup for shared libraries. More... | |
static std::string | getNativeName (const std::string &name) |
Given a shared library name without file extensions, prefixes and nor suffixes it will construct a library name according to the specifc platform. More... | |
static std::string | getSearchPath () |
Returns the system lookup path. More... | |
static void | resetSearchPath () |
Comes back the application lookup path to the original state, before any add_search_dir has been called. More... | |
Private Attributes | |
Impl * | m_pimpl |
A class for handling shared libraries (DLLs, SO, DyLibs).
You can use this class to load any shared library and acces any address inside it.
If the shared library you are attempting to load has dependencies the other shared libraries must be in a folder reachable by the operational system.
On Mac OS X the environment variables PATH, DYLD_LIBRARY_PATH, DYLD_FALLBACK_LIBRARY_PATH and DYLD_FRAMEWORK_FALLBACK_PATH may be set to indicate the list of folders containing shared libraries.
On Linux the environment variables PATH and LD_LIBRARY_PATH may be used to indicate the folders searchable by the operational system.
On Windows you can set the environment variable PATH.
Note that this class has a special static method (or class method) named addSearchDir that can be used to control the behaviour of operational system when loading the shared library dependencies.
te::core::Library::Library | ( | const std::string & | slib_file_name, |
const bool & | delay_load = false |
||
) |
Load a new shared library.
The file name may be a relative or absolute path.
If just the name of the shared library is given the class will look for the library in the operational system specific locations.
slib_file_name | The library file name. The file name may contain the full library path. |
delay_load | If true the client object must call explicitly the load method before trying to access any symbol in the library. |
LibraryLoadException | It can throw an exception if delay_load is set to false and the library can not be loaded. |
LibraryNameException | It throws an exception if library name is empty or just white-spaces. |
te::core::Library::~Library | ( | ) |
The destructor automatically unloads from memory the shared library if it was not unloaded explicitly.
|
static |
Add the informed dir to the path used by the operational system to lookup for shared libraries.
dir_name | A directory to be added to the lookup of shared libraries. |
LibraryInvalidSearchPathException | It throws an exception if the path couldn't be added to the search path. |
void* te::core::Library::getAddress | ( | const char * | symbol | ) | const |
Return the address where the given symbol is loaded into memory.
symbol | The name of the symbol inside the library you are searching for. It may be for instance a function name. |
LibrarySymbolNotFoundException | It throws an exception if it is not possible to locate the given symbol. |
const std::string& te::core::Library::getFileName | ( | ) | const |
Return the shared library file name as informed in the constructor.
|
static |
Given a shared library name without file extensions, prefixes and nor suffixes it will construct a library name according to the specifc platform.
|
static |
Returns the system lookup path.
LibrarySearchPathException | It throws an exception if the path couldn't be reset. |
bool te::core::Library::isLoaded | ( | ) | const |
Return true if the shared library is loaded otherwise return false.
void te::core::Library::load | ( | ) |
Load the shared library to memory.
If the shared library was already loaded this method doesn't perform operations.
LibraryLoadException | If the shared library can not be loaded to memory. |
|
static |
Comes back the application lookup path to the original state, before any add_search_dir has been called.
LibraryResetSearchPathException | It throws an exception if the path couldn't be reset. |
void te::core::Library::unload | ( | ) |
Force the unload of the shared library from memory.
If the library wasn't previously loaded or if it was already unloaded this method doesn't perform operations.
LibraryUnloadException | If the library can not be unload from memory this method raises an exception. |