Sharing data with a dynamically loaded library (dlopen, dlsym)

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);

/* do something */

hello_t hello = (hello_t) dlsym(handle, "hello");
hello(testing);

In the dynamic library


#include 
#include "main.h"

extern "C" void hello( void (*fn)() ) {
  /*do something and then invoke callback function from main */  fn();
}


Are there other ways to enable functions / data of the main call / use from the dynamic library besides using callbacks?

+3
source share
1 answer

, , . , , , DLL , , , .

, , , , , /. , , , , .

+2

Source: https://habr.com/ru/post/1759050/


All Articles