How to create and download a GTK module?

I want to create a custom GTK module that must be loaded when the GTK application starts.

Documentation on this topic is rare, I searched a lot, but I could not start it. I am on Ubuntu Linux with GTK3 and tried sofar:

  • Compiled and linked to a shared library with a method void gtk_module_init(gint *argc, gchar ***argv[])inside. As I understand it, this should be enough to create a simple module. Full code:
#include <iostream>
#include <gtk/gtk.h>

void gtk_module_init(gint *argc, gchar ***argv[]) {
    std::cout << "huhu" << std::endl;
}
  • Put this library in / usr / lib / x 86_64-linux-gnu / gtk-3.0 / modules / libtest-gtk-module.so
  • I tried to run the application as follows: gnomine --gtk-module=libtest-gtk-module.soBut all I get is:Gtk-Message: Failed to load module "libtest-gtk-module.so"

So what else needs to be done to get GTK to load this library?

Thank you very much in advance!

+5
source share
2

. ldconfig root. .

[EDIT]

:

  • ++, , mangled:

    extern "C" {
    void gtk_module_init(gint *argc, gchar ***argv[]) {
        std::cout << "huhu" << std::endl;
    }
    }
    
  • :

    g++ -fPIC -shared -Wl,-soname,libfoo.so.1 -olibfoo.so.1.0.1 `pkg-config --libs --cflags gtk+-3.0` t.c
    
  • , ldconfig, , , :

    ~$ gedit --gtk-module=/home/eric/libfoo.so.1.0.1 t.c
    huhu
    

Mint LMDE, Ubuntu, , .

+2

strace:

strace -eopen add_your_command_here 2>&1 | grep libtest-gtk-module.so

, .

0

All Articles