Running a gtk2 program outside the msys2 shell

215 views Asked by At

excuse me if I bring to your attention a problem concerning the old GTK2 which is no longer supported.

I need to compile a program written in C/GTK2 on windows.

Glade-2 and DEVc++ were a good solution but the pango libraries are outdated and many features are missing.

I compiled successfully with MSYS2 however the program run outside the shell does not load the theme and the icons.

Through ldd i read all the libraries needed to start the program and I put them in the same folder as the executable, i also added the contents of /lib/gdk-pixbuf-2.0/2.10.0/loaders without result.

I did these other tests which are valid for GTK3:

From MSYS2 I copied share/themes/Windows10/gtk-2.0 to the program folder

Also from MSYS2 I copied etc/gtk-2.0 into the program folder and inside it I created the settings.ini file with these lines:

[Settings]

gtk-theme-name=Windows10 gtk-font-name=Segoe UI 9

at last I ran:

$ glib-compile-schemas /mingw64/share/glib-2.0/schemas/ --targetdir=/c/openhemp/bin/

None of this seems to work, the program keeps launching with no theme and no icons.

I'm sure that some library is still missing on startup in fact if I run from shell typing

/c/openhemp/bin/openhemp.exe again starts with no icons as I type cd /c/openhemp/bin openhemp.exe without specifying the path starts correctly.

At this point I'm out of ideas, I hope you can help me

Thanks in advance

Paul

I searched for documentation without finding any specific reference

1

There are 1 answers

1
Paolo Bongiorno On

Porting GTK2/GTK3 programs to windows using Msys2

• Download, install MSYS2 • update with pacman -Syuu

Install the gtk2/gtk3 development environment:

32-bit

pacman -S autoconf

pacman -S mingw-w64-i686-glib2

pacman -S glib2-devel

pacman -S automake

pacman -S mingw-w64-i686-gtk2

pacman -S mingw-w64-i686-gtk-engine-murrine

pacman -S mingw-w64-i686-glade-gtk2

pacman -S mingw-w64-i686-gtk3

pacman -S mingw-w64-clang-i686-libglade

pacman -S base-devel

pacman -S mingw-w64-i686-toolchain

64 bit

pacman -S mingw-w64-x86_64-glade

pacman -S mingw-w64-x86_64-glib2

pacman -S mingw-w64-x86_64-gtk2

pacman -S mingw-w64-x86_64-gtk-engine-murrine

pacman -S mingw-w64-x86_64-glade-gtk2

pacman -S mingw-w64-x86_64-gtk3

pacman -S mingw-64-clang-x86_64-libglade

pacman -S mingw-w64-x86_64-libglade

pacman -S mingw-w64-x68_64-toolchain

Creating the program tree outside the MSYS2 environment

mkdir /c/myfolder

mkdir /c/myfolder/bin

mkdir /c/myfolder/etc

mkdir /c/myfolder/img

mkdir /c/myfolder/lib

mkdir /c/myfolder/share

mkdir /c/myfolder/share/glib-2.0

mkdir /c/myfolder/share/themes

• Put the executable in the bin folder 
• run: ldd ./myprogram 
• transfer all required dlls to the bin folder except those belonging to windows.

To load the launcher theme:

GTK2

mkdir /c/myfolder/etc/gtk-2.0

create the gtkrc file by inserting this line

gtk-theme-name="Windows10"

cp -r /c/msys64/mingw64/lib/gtk-2.0 /c/myfolder/lib/

GTK3

mkdir /c/myfolder/etc/gtk-3.0

create the settings.ini file by inserting these lines:

[Settings] gtk-theme-name=Windows10

gtk-font-name=Segoe UI 9

cp -r /c/msys64/mingw64/lib/gtk-3.0 /c/myfolder/lib/

Download the Windows 10 theme from Gnome-look and unpack it in the share/themes folder

Open msys2 shell and create schema in “/c/myfolder/share/glib-2.0”

glib-compile-schemas /mingw64/share/glib-2.0/schemas/ --targetdir=/c/myfolder/share/glib-2.0

Loading Icons:

cp -r /c/msys64/lib/gdk-pixbuf-2.0 /c/myfolder/lib

In the root folder of our program we have created the img folder but this depends on where in our program we have decided to look for the icons, in the case of GTK2 if we want to look for them in /c/myfolder/img, in our main.c we will write:

pixmap_dir = strdup("../img");

add_pixmap_directory (pixmap_dir);