title: How do I get a return value from a shared library function?
body: <p>I read a few tutorials about loading shared libraries and call functions in them. I succeded on both points. There's just one thing I didn't see in any of the tutorials:</p>
  
  <p>How do I return a value from a function in a shared library to the main code?</p>
  
  <p>This is my shared library source:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  char* entry(){
    printf("this is a working plugin\n");
  
    return "here we go!";
  }
  </code></pre>
  
  <p>When i call it, i get "this is a working plugin" on the stdout. My question is now, how i can get the "here we go" string back to the main.c which looks like:</p>
  
  <pre><code>void *lib_handle;
  void (*lib_func)();
  
  ...
  
  lib_handle = dlopen("/home/tectu/projects/tibbers/plugins.so", RTLD_LAZY);
  if(!lib_handle)
    error("coudln't load plugins", NULL);
  
  lib_func = dlsym(lib_handle, "entry");
    if(!lib_func)
      error("coudln't find symbol in plugin library", NULL);
  
  (*lib_func)();  // here i call the entry() from the .so
  </code></pre>
  
  <p>Something like this does not work:</p>
  
  <pre><code>printf("return value: %s\n, (*lib_func)());
  </code></pre>
  
  <p>So, any ideas?</p>
  
  <p>Thank you.</p>