λ61
Loading...
Searching...
No Matches
loadSharedLibrary.h File Reference

Go to the source code of this file.

Macros

#define L61_ROSETTA_CAST_SYMBOL(type, symbol)

Functions

l61_rosetta_SharedLibrary_handle_t l61_rosetta_loadSharedLibrary (const char *file)
l61_rosetta_SharedLibrary_symbol_t l61_rosetta_getSharedLibrarySymbol (l61_rosetta_SharedLibrary_handle_t handle, const char *symbol)
int l61_rosetta_unloadSharedLibrary (l61_rosetta_SharedLibrary_handle_t handle)
const char * l61_rosetta_getSharedLibraryLoaderError ()

Detailed Description

// Load a library in C99
void* handle = l61_rosetta_loadSharedLibrary("./mylib.so");
if (!handle) {
printf("Error: %s\n", l61_rosetta_getSharedLibraryLoaderError());
return -1;
}
// Get a function pointer
int (*my_func)(int) = L61_ROSETTA_CAST_SYMBOL(
int(*)(int),
l61_rosetta_getSharedLibrarySymbol(handle, "my_function")
);
// Use and cleanup
if (my_func) {
int result = my_func(42);
}
l61_rosetta_SharedLibrary_symbol_t l61_rosetta_getSharedLibrarySymbol(l61_rosetta_SharedLibrary_handle_t handle, const char *symbol)
Definition loadSharedLibrary.c:42
#define L61_ROSETTA_CAST_SYMBOL(type, symbol)
Definition loadSharedLibrary.h:71
int l61_rosetta_unloadSharedLibrary(l61_rosetta_SharedLibrary_handle_t handle)
Definition loadSharedLibrary.c:52
l61_rosetta_SharedLibrary_handle_t l61_rosetta_loadSharedLibrary(const char *file)
Definition loadSharedLibrary.c:31
const char * l61_rosetta_getSharedLibraryLoaderError()
Definition loadSharedLibrary.c:62

Macro Definition Documentation

◆ L61_ROSETTA_CAST_SYMBOL

#define L61_ROSETTA_CAST_SYMBOL ( type,
symbol )
Value:
((type)(symbol))

Function Documentation

◆ l61_rosetta_getSharedLibraryLoaderError()

const char * l61_rosetta_getSharedLibraryLoaderError ( )

Retrieves a description of the last shared library loading error. On POSIX systems, this wraps dlerror(). On Windows, it provides a formatted system error message.

Warning
The returned string is stored in thread-local storage on POSIX systems but uses a static buffer on Windows (not thread-safe on Windows).
Returns
A pointer to a string describing the last error. !!DO NOT FREE!!

◆ l61_rosetta_getSharedLibrarySymbol()

l61_rosetta_SharedLibrary_symbol_t l61_rosetta_getSharedLibrarySymbol ( l61_rosetta_SharedLibrary_handle_t handle,
const char * symbol )

Gets a symbol from a shared library.

Parameters
handleHandle to the loaded library.
symbolName of the symbol to retrieve.
Warning
Do mind C++ symbol mangling
Returns
Pointer to the requested symbol, or NULL if the symbol is not found.

◆ l61_rosetta_loadSharedLibrary()

l61_rosetta_SharedLibrary_handle_t l61_rosetta_loadSharedLibrary ( const char * file)

Loads a shared library.

Parameters
filePath to the library.
Returns
Handle to the loaded library, or NULL on failure.

◆ l61_rosetta_unloadSharedLibrary()

int l61_rosetta_unloadSharedLibrary ( l61_rosetta_SharedLibrary_handle_t handle)

Unloads a shared library.

Parameters
handleHandle to the loaded library.
Returns
0 on success, -1 on failure.