Look up the address of the named function in a shared object.
Defined in <SDL3/SDL_loadso.h>
const char *name); SDL_FunctionPointer SDL_LoadFunction(SDL_SharedObject *handle,
SDL_SharedObject * | handle | a valid shared object handle returned by SDL_LoadObject(). |
const char * | name | the name of the function to look up. |
(SDL_FunctionPointer) Returns a pointer to the function or NULL on failure; call SDL_GetError() for more information.
This function pointer is no longer valid after calling SDL_UnloadObject().
This function can only look up C function names. Other languages may have name mangling and intrinsic language support that varies from compiler to compiler.
Make sure you declare your function pointers with the same calling convention as the actual library function. Your code will crash mysteriously if you do not do this.
If the requested function doesn't exist, NULL is returned.
It is safe to call this function from any thread.
This function is available since SDL 3.1.3.
/* Variable declaration */
SDL_SharedObject* myHandle = NULL;const char* myFunctionName = "myFancyFunction";
void (*myFancyFunction)(int anInt);
/* Dynamically load mylib.so */
"mylib.so");
myHandle = SDL_LoadObject(
/* Load the exported function from mylib.so
* The exported function has the following prototype
* void myFancyFunction(int anInt);
*/
void (*)(int))SDL_LoadFunction(myHandle, myFunctionName);
myFancyFunction = (
/* Call myFancyFunction with a random integer */
if (myFancyFunction != NULL) {
15);
myFancyFunction(else {
} /* Error handling here */
}