Shared library loader. More...

#include <cxxtools/library.h>

Public Member Functions

 Library ()
 Default Constructor which does not load a library.
 Library (const std::string &path)
 Loads a shared library.
 Library (const Library &other)
Libraryoperator= (const Library &other)
 ~Library ()
 The destructor unloads the shared library from memory.
Libraryopen (const std::string &path)
 Loads a shared library.
void close ()
void * operator[] (const char *symbol) const
 Resolves the symbol symbol from the shared library Returns the address of the symbol or 0 if it was not found.
void * resolve (const char *symbol) const
 Resolves the symbol symbol from the shared library Returns the address of the symbol or 0 if it was not found.
 operator const void * () const
 Returns null if invalid.
Symbol getSymbol (const char *symbol) const
bool operator! () const
 Returns true if invalid.
const std::string & path () const
 Returns the path to the shared library image.

Static Public Member Functions

static std::string suffix ()
 Returns the extension for shared libraries.
static std::string prefix ()
 Returns the prefix for shared libraries.

Protected Member Functions

void detach ()

Detailed Description

Shared library loader.

This class can be used to dynamically load shared libraries and resolve symbols from it. The example below shows how to retrieve the address of the function 'myProcedure' in library 'MyLibrary':

Library shlib("MyLibrary.dll");
void* procAddr = shlib["myProcedure"];
typedef int (*MyProcType)();
MyProcType proc =(MyProcType)procAddr;
int result = proc();

Constructor & Destructor Documentation

cxxtools::Library::Library ( )

Default Constructor which does not load a library.

cxxtools::Library::Library ( const std::string &  path)
explicit

Loads a shared library.

If a file could not be found at the given path, the path will be extended by the platform-specific shared library extension first and then also by the shared library prefix. If still no file can be found an exception is thrown.

The library is loaded immediately.

cxxtools::Library::Library ( const Library other)
cxxtools::Library::~Library ( )

The destructor unloads the shared library from memory.

Member Function Documentation

void cxxtools::Library::close ( )
void cxxtools::Library::detach ( )
protected
Symbol cxxtools::Library::getSymbol ( const char *  symbol) const
Library& cxxtools::Library::open ( const std::string &  path)

Loads a shared library.

If a file could not be found at the given path, the path will be extended by the platform-specific shared library extension first and then also by the shared library prefix. If still no file can be found an exception is thrown. Calling this method twice might close the previously loaded library.

cxxtools::Library::operator const void * ( ) const

Returns null if invalid.

bool cxxtools::Library::operator! ( ) const

Returns true if invalid.

Library& cxxtools::Library::operator= ( const Library other)
void* cxxtools::Library::operator[] ( const char *  symbol) const
inline

Resolves the symbol symbol from the shared library Returns the address of the symbol or 0 if it was not found.

const std::string& cxxtools::Library::path ( ) const

Returns the path to the shared library image.

static std::string cxxtools::Library::prefix ( )
static

Returns the prefix for shared libraries.

Returns "lib" on Linux, "" on Windows

void* cxxtools::Library::resolve ( const char *  symbol) const

Resolves the symbol symbol from the shared library Returns the address of the symbol or 0 if it was not found.

static std::string cxxtools::Library::suffix ( )
static

Returns the extension for shared libraries.

Returns ".so" on Linux, ".dll" on Windows.


The documentation for this class was generated from the following file: