Mapped from RTLD_NOW, RTLD_LAZY, RTLD_GLOBAL and RTLD_LOCAL
Obtains the address of a symbol within the shared library
Obtains the address of a symbol within the shared library
Unloads the OS-specific shared library associated with this SharedLib instance.
Unloads the OS-specific shared library associated with this SharedLib instance.
Returns the path to the OS-specific shared library associated with this object.
Loads an OS-specific shared library.
Loads an OS-specific shared library.
Returns the total number of libraries currently loaded by SharedLib
void main() { if (auto lib = SharedLib.load(`c:\windows\system32\opengl32.dll`)) { Trace.formatln("Library successfully loaded"); void* ptr = lib.getSymbol("glClear"); if (ptr) { Trace.formatln("Symbol glClear found. Address = 0x{:x}", ptr); } else { Trace.formatln("Symbol glClear not found"); } lib.unload(); } else { Trace.formatln("Could not load the library"); } assert (0 == SharedLib.numLoadedLibs); }
This implementation uses reference counting, thus a library is not loaded again if it has been loaded before and not unloaded by the user. Unloading a SharedLib decreases its reference count. When it reaches 0, the shared library associated with it is unloaded and the SharedLib instance is deleted. Please do not delete SharedLib instances manually, unload() will take care of it.
Note: SharedLib is thread-safe.
SharedLib is an interface to system-specific shared libraries, such as ".dll", ".so" or ".dylib" files. It provides a simple interface to obtain symbol addresses (such as function pointers) from these libraries.