title: error at dlsym(): ./dynlibrary: undefined symbol: method
body: <p>I've got an issue I am not able to solve. Looked up everything I found so far.
  My problem is, I create a dyn library in my program a want to dlopen it and dlsym a method out of that lib.</p>
  
  <p>It seems that dlopen works but dlsym return me the error "<strong>undefined symbol: method</strong>"</p>
  
  <p>where "<strong>method</strong>" is the name of the method I passed to dlsym.</p>
  
  <p>Here is how I create the library:</p>
  
  <pre><code>execl("/usr/bin/gcc", "gcc", "-fPIC", "-Wall", "-g", "-c", "userinput.c", NULL);
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>execl("/usr/bin/gcc", "gcc", "-ggdb3", "-shared", 
        "-Wl,-soname,libuserinput.so.1", "-o", "libuserinput.so.1.0",
    "userinput.o", "-lc", NULL);
  </code></pre>
  
  <p>This should work as there is a library after running my code.</p>
  
  <p>I open the library like this:</p>
  
  <pre><code>static void *my_load_dyn (const char *lib) {
  static void *handle;
  handle = dlopen ("./libuserinput.so.1.0", RTLD_NOW | RTLD_DEEPBIND);
  if (handle == NULL) {
    printf ("error at dlopen(): %s\n", dlerror ());
    exit (EXIT_FAILURE);
  }
  return handle;
  }
  
  /* load func from dyn lib"*/
  static void *my_load_func (void *handle, char *func) {
    void *funcptr = dlsym (handle, func);
    if (funcptr == NULL) {
      printf ("error at dlsym(): %s\n", dlerror ());
      exit (EXIT_FAILURE);
    }
    return funcptr;
  }
  </code></pre>
  
  <p>and call those functions like this:</p>
  
  <pre><code>void *libhandle;
  void (*userMethod) (unsigned char *d);
  
  libhandle = my_load_dyn(LIBUSERINPUT);
  userMethod = my_load_func(libhandle, "testMethod");
  (*userMethod)(d);
  </code></pre>
  
  <p>EDIT:
  here is the code from the userinput.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  void testMethod(unsigned char *d)
  {
  d[0] = 'Z';
  }
  </code></pre>
  
  <p>It is generated in my programm and also compiled and linked in the running programm</p>