carb::extras::getLibrarySymbol

Defined in carb/extras/Library.h

template<typename T>
T carb::extras::getLibrarySymbol(LibraryHandle libHandle, const char *name)

Attempts to retrieve the address of a symbol from a loaded module.

Note

The libHandle parameter may also be nullptr to achieve some special behavior when searching for symbols. However, note that this special behavior differs between Windows and Linux. On Windows, passing nullptr for the library handle will search for the symbol in the process’s main module only. Since most main executable modules don’t export anything, this is likely to return nullptr. On Linux however, passing nullptr for the library handle will search the process’s entire symbol space starting from the main executable module.

Note

Calling this on Linux with the handle of a library that has been unloaded from memory is considered undefined behavior. It is the caller’s responsibility to ensure the library handle is valid before attempting to call this. On Windows, passing in an invalid library handle will technically fail gracefully, however it is still considered undefined behavior since another library could be reloaded into the same space in memory at a later time.

Parameters
  • libHandle[in] The library to retrieve the symbol from. This should be a handle previously returned by loadLibrary().

  • name[in] The name of the symbol to retrieve the address of. This must exactly match the module’s exported name for the symbol including case.

Returns

The address of the loaded symbol if successfully found in the requested module.

Returns

nullptr if the symbol was not found in the requested module.