c++ - Can I access to symbols of the host process from a shared object loaded in runtime? Any alternative? -


in scenario want plugin, shared object loaded in runtime, access symbols “host application” can add functionality application.

i have tried have not found way , have no clue on whether possible or not. so, can somehow or there alternative applications use plugins use?

i on fedora 15, linux 2.6.4. however, hope solution cross-platform.

there 3 main approaches:

  1. pass structure of function pointers dll application, giving access whatever symbols want share. portable method, kind of pain create function pointers. like:

    // in shared header struct app_vtable {   void (*appfoo)(); };  // in plugin: const app_vtable *vt; void set_vtable(const app_vtable *vt_) {   vt = vt_; }  void bar() {   vt->appfoo(); }  // in application: void foo(); const app_vtable vt = { foo };  void loadplugin() {   void *plugin = dlopen("plugin.so", rtld_lazy);   void (*pset_vtable)(const app_vtable *) = dlsym(plugin, "set_vtable");    pset_vtable(&vt);    void (*pbar)() = dlsym(plugin, "bar");   pbar(); } 
  2. move application library, , have executable link in library , call entry point in it. plugins can link same library , access symbols easily. quite portable, can result in performance loss due need use position-independent code in main app library (although may able away fixed mapping in case, depending on architecture).

  3. on linux (and possible other elf platforms) can use -rdynamic export symbols application executable directly. isn't portable other platforms - in particular, these no equivalent on windows.

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -