1

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.

exporting 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.

exilit
  • 1,156
  • 11
  • 23
  • Thank you very much. I think this should be exactly what I was searching for. Just could not find it. Would like to mark it as solved. – exilit Feb 26 '14 at 10:00
  • @exilit just upvote the other question and/or answer(s), if you feel they deserve it, and delete your own question. – manuell Feb 26 '14 at 18:11

0 Answers0