c++ - Dynamically load gtkmm objects with dlopen -


i have dynamically use library uses gtkmm. unfortunately, don't manage open window in way, , don't understand why. due technical restrictions, functions must use dl* family. here have tried far :

my compile lines:

for library:

g++ gtkmm.cpp -shared -fpic -o lib.so `pkg-config gtkmm-3.0 --cflags --libs 

for main:

g++ main.cpp -ldl 

file: main.cpp

#include "inibbler.hpp" #include <dlfcn.h> #include <cstdlib> #include <iostream>  typedef inibbler *(*fptr)(int x, int y);  int main(int ac, char **av) {   void  *handle;   fptr  ptr;    handle = dlopen("./lib.so", rtld_lazy);   if (handle != null)     {       ptr = reinterpret_cast<fptr>(dlsym(handle, "returninstance"));       inibbler *test = reinterpret_cast<inibbler *>((*ptr)(700, 500));       test->loopgame(ac, av);     } } 

file: gtkmm.cpp

libgtkmm::libgtkmm(int x, int y) {   (void)x;   (void)y;   this->set_default_size(100, 100); }  libgtkmm::~libgtkmm() {  }  void libgtkmm::loopgame(int ac, char **av) {   glib::refptr<gtk::application> app     = gtk::application::create(ac,av, "org.gtkmm", gio::application_handles_open);    app->run(*this); }  extern "c" {   inibbler *returninstance(int x, int y)   {     std::cout << "hey" << std::endl;     return (new libgtkmm(x, y));   } } 

file: gtkmm.hpp

#ifndef gtkmm_h_ #define gtkmm_h_  #include <gtkmm.h> #include "../inibbler.hpp"  class   libgtkmm : public inibbler, public gtk::window { private: public:   libgtkmm(int x, int y);   virtual ~libgtkmm();   virtual void loopgame(int ac, char **av); };  #endif  // !gtkmm_h_ 

file: inibbler.hpp

#ifndef inibbler_hpp_ # define inibbler_hpp_  class   inibbler { public:   virtual void  loopgame(int ac, char **av) = 0; };  #endif /* !inibbler_hpp_ */ 

when call app->run, window not open itself, , got lot of gtk fail messages... telling pointer somehow null. here notable:

(process:7556): gtk-critical **: gtk_settings_get_for_screen: assertion 'gdk_is_screen (screen)' failed  (process:7556): glib-gobject-warning **: invalid (null) pointer instance  (process:7556): glib-gobject-critical **: g_signal_connect_object: assertion 'g_type_check_instance (instance)' failed 

does have idea of how can resolve problem ?

problem: don't have gtk::main.

solution: create gtk::main. need this:

gtk::main main(argc, argv); main.run(); 

to avoid gtkmm freaking out, create gtk::main possible. call main.run() once you've initialized everything.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -