Gtk+ icon missing when running in MS Windows

2019-04-15 16:40发布

问题:

I have a C/GTK+ application developed on Ubuntu, and I want to cross-compile it so that it runs on MS Windows.

I followed this guide to set up the compiler, and the program was compiled successfully, and it runs on MS Windows.

However, the icons on a Search Entry were missing.

This is what I get when I'm on Ubuntu:

This is what I get when I run the program in MS Windows (or Wine):

In addition, the terminal shows the following:

(main.exe:8): Gtk-WARNING **: Could not find the icon 'edit-find-symbolic'. The 'hicolor' theme
was not found either, perhaps you need to install it.
You can get a copy from:
    http://icon-theme.freedesktop.org/releases

Question: Is it possible to have the icons showing up in Windows, without the need to install anything on the Windows box? My application aims at being able to run from a USB flash drive without installing anything.

The relevant part of the Glade file I used to create the application, in case it's useful:

          <object class="GtkSearchEntry" id="searchentry1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="primary_icon_name">edit-find-symbolic</property>
            <property name="primary_icon_activatable">False</property>
            <property name="primary_icon_sensitive">False</property>
          </object>

Things I've tried so far: copying edit-find-symbolic.svg to the directory containing main.exe (i.e. together with the dlls); copying the whole directory /usr/share/icons/gnome there. None of these worked.


Update:

In the directory containing main.exe I added a subdirectory share, and in it another subdirectory icons. I placed edit-find-symbolic.svg in this subdirectory. The search icon still looks the same (doesn't work), but the terminal output this time is different:

(main.exe:8): GLib-GIO-CRITICAL **: g_loadable_icon_load: assertion `G_IS_LOADABLE_ICON (icon)' failed

If edit-find-symbolic.svg is not present in this folder, but a folder named hicolor is present, the icon still doesn't work, and this time there isn't any output in the terminal at all.

回答1:

This is a late reply but I encountered this issue and I have solved it with the following steps:

SVG icons of the default theme (adwaita) needs to be copyed to a share directory relative to the bin directory bin../share/icons/Adwaita/scalable/* also bin../share/icons/Adwaita/icon-theme.cache and bin../share/icons/Adwaita/index.theme

After several test, it appears that the following files are also required:

lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.dll
lib/gdk-pixbuf-2.0/2.10.0/loaders/loaders.cache

The first line of this loaders.cache file also needs to be edited to "../lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.dll"

The file tree looks like this:

bin/gtkapplication.exe
bin/*.dll
share/loader.cache
share/glib-2.0/gschemas.compiled
share/icons/Adwaita/scalable/*
share/icons/Adwaita/icon-theme.cache
share/icons/Adwaita/index.theme
lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.dll
lib/gdk-pixbuf-2.0/2.10.0/loaders/loaders.cache

Example application: https://github.com/odrevet/gtk-sample-app



回答2:

As a workaround I have converted the icons from svg to png, then placing them in share/icons. The icons now show up, though there is a minor problem: when the search entry is empty, an additional magnifying glass icon will shop up on the right.

The additional magnifying glass will be replaced by the "clear" icon when there is text in the entry, so I do not consider this that much of a problem... (Although admittedly it looks quite weird...)

As this is only a workaround and not a perfect solution, I will not mark this as accepted answer. I think the problem may be related to how the svg files are displayed, but I have all the DLLs from here so I don't really understand what the problem is.