title: Dynamic Library Function Call
body: <p>I have the following code which simply loads the library test.so from the current directory and executes the <code>version</code> function within that library. What should be returned is a string. What is instead returned is junk from the stack(a pointer location maybe?). Does anyone have any idea why the following code would be failing.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;dlfcn.h&gt;
  
  int main(int argc, char **argv){
      void *handler;
      char *(*version);
      char *error;
  
      handler = dlopen("./test.so", RTLD_LAZY);
      if(!handler){
          fprintf(stderr, "%s\n", dlerror());
          exit(EXIT_FAILURE);
      }
  
      dlerror(); //Flushes any existing error
  
      *(void **)(&amp;version) = dlsym(handler, "version");
  
      if((error = dlerror()) != NULL){
          fprintf(stderr, "%s\n", error);
          exit(EXIT_FAILURE);
      }
      printf("%s\n", version);
      dlclose(handler);
      exit(EXIT_SUCCESS);
  }
  </code></pre>