My main program would load the hello.so simple dynamic library
In the main
void* handle = dlopen("./hello.so", RTLD_LAZY);
In the main, pass a callback function called testing (defined somewhere in main.h) and call hello () from the dynamic library
typedef void (*callback)();
typedef void (*hello_t)( callback);
hello_t hello = (hello_t) dlsym(handle, "hello");
hello(testing);
In the dynamic library
#include
#include "main.h"
extern "C" void hello( void (*fn)() ) {
fn();
}
Are there other ways to enable functions / data of the main call / use from the dynamic library besides using callbacks?
source
share