Search code examples
pythonlinuxgtkshared-librarieswnck

How to fix the error: Cannot load shared library , symbol undefined


I have a python script that is converted to a 'one file executable' using pyinstaller. The executable runs in my computer without any problem. When it runs in another computer one of the threads seems to stop working where gtk and wnck are used.

Failed to load shared library 'libwnck-3.so.0' referenced by the typelib: /usr/lib/x86_64-linux-gnu/libwnck-3.0.so.0: undefined symbol: gdk_display_get_monitor_at_window

The above warning is displayed as soon as the executable is run in the other computer's terminal(I guess when it reads the import statement).

An error is thrown when the it reaches the following line;

screen = Wnck.Screen.get_default()

GLib.GError: g-invoke-error-quark: Could not locate wnck_screen_get_default: /usr/lib/x86_64-linux-gnu/libwnck-3.0.so.0: undefined symbol: gdk_display_get_monitor_at_window (1)

The following function is threaded where the error occurs

import gi
gi.require_version('Wnck', '3.0')
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Wnck

def my_window():
    screen = Wnck.Screen.get_default()  -- this line throws error
    screen.force_update()
    while True:
        time.sleep(.5)
        while Gtk.events_pending():
            Gtk.main_iteration()
        new_window = screen.get_active_window()
        ....
        ....

I am using - Ubuntu 16.04, xenial. | version of libgtk-3-0: 3.18.9

Other computer uses - Ubuntu 18.04.4 bionic | version of libgtk-3-0: 3.22.30


Solution

  • The copy of libwnck you're using was compiled against a version of GDK that contains the gdk_display_get_monitor_at_window() function, but the copy of GDK you have installed on your system does not contain this function.

    The gdk_display_get_monitor_at_window() function was introduced in GTK 3.22, so you must make sure that you have GDK 3.22 or later installed.