I need currently some Help.
The Question in short:
How can i reference from a shared object (dynamic library) into the application which loaded the library dynamically with dlopen
?
Now the context:
I am developing under Linux in C. While building a kind of plug-in System with dynamic loadable libraries i need a feature which i would call back reference (probably that's the Problem: I don't know what to search for). What I mean by back reference is the following:
Presume that there are two "modules": main_app.c (the main application)
/* main_app.c */
int main(void){
void *dl_handle;
/* load DL and symbols */
dl_handle = dlopen("dyn_lib", RTLD_NOW);
}
void should_be_called_from_library(void){
// DO SOMETHING USEFULL
}
and dyn_lib.c (The DL)
/* dyn_lib.c */
#include main_app.h
/* anywhere in the DL: call a function from the main application */
should_be_called_from_library(void);
/* .... */
So what I want to do is to call a symbol in the main application from the dynamically loaded library. Everything else works fine, but if i try to call the function (or address any other symbol), the library cannot be loaded.
export
ing the symbol in the C code didn't help either so I assume the problem is with the linker during the build process of main_app.c
. Because dyn_lib.c
needs the symbol to locate the function.