title: Getting undefined symbol error while dynamic loading of shared library
body: <p>I am getting <code>undefined symbol</code> error while loading library dynamically.
  Here is my code snippet that generates this error :</p>
  
  <pre><code>int main ()
  {
  
      void *lib_handle = NULL;
  
      MyClass* (*create)();
      void (*destroy)(MyClass*);
      char *error;
  
  
      lib_handle = dlopen ("./libshared.so", RTLD_LAZY);
  
      if (lib_handle == NULL) 
      {
          fprintf(stderr, "%s\n", dlerror());
          exit(1);
  
      } 
  
      create = (MyClass* (*)()) dlsym(lib_handle, "create_object");
      if ((error = dlerror()) != NULL)  
     {
        fprintf(stderr, "%s\n", error);
        exit(1);
     }
  
      destroy = (void (*)(MyClass*)) dlsym(lib_handle, "destroy_object");
  
      MyClass *myClass = (MyClass*) create;
      destroy(myClass);   
  
      dlclose(lib_handle);
  }
  </code></pre>
  
  <p>But when I load library simply by commenting above code and exporting library path everything works like charm.</p>
  
  <p>For dynamic linking I am using the following command on command prompt.</p>
  
  <p><code>g++ -Wl,--export-dynamic shared_user.cpp -ldl</code></p>
  
  <p>Any help would be appreciated.</p>