Using Gtk (lablgtk) on Windows

I am truying to install Gtk and use it with Ocaml (lablgtk) on Windows (the Diskuv package).The GTK Project - A free and open-source cross-platform widget toolkit proposes me to use MSYS2 and pacman to install mingw-w64-x86_64-gtk3 . I had to install mingw-w64-x86_64-pkg-config too. And add the \MSYS64\mingw64\bin to the PATH.

Now, opam install lablgtk3… And I have the error :

#=== ERROR while compiling cairo2.0.6.2 =======================================#
# context     2.2.0~alpha~dev | win32/x86_64 | ocaml-system.4.12.1 | pinned(
# path        C:\Users\frede\AppData\Local\opam\playground\.opam-switch\build\cairo2.0.6.2
# command     C:\Users\frede\AppData\Local\Programs\DISKUV~1\0\dkml\_opam\bin\with-dkml.exe dune build -p cairo2 -j 7
# exit-code   1
# env-file    C:\Users\frede\AppData\Local\opam\log\cairo2-10080-f346a0.env
# output-file C:\Users\frede\AppData\Local\opam\log\cairo2-10080-f346a0.out
### output ###
#           cl src/cairo_stubs.obj (exit 2)
# (cd _build/default/src && C:\DiskuvOCaml\BuildTools\VC\Tools\MSVC\14.26.28801\bin\HostX64\x64\cl.exe -nologo -O2 -Gy- -MD -D_CRT_SECURE_NO_DEPRECATE -nologo -O2 -Gy- -MD -Id:/msys64/mingw64/include -Id:/msys64/mingw64/include/freetype -Id:/msys64/mingw64/lib/glib-2.0/include -Id:/msys64/mingw64/lib/glib-2.0/include/freetype -Id:/msys64/mingw64/include/glib-2.0 -Id:/msys64/mingw64/include/glib[...]
# cairo_stubs.c
# C:\Users\frede\AppData\Local\opam\playground\.opam-switch\build\cairo2.0.6.2\_build\default\src\cairo_macros.h(178): error C2010: '.' : inattendu dans la liste de paramètres de macro
# cairo_stubs.c(1615): error C2010: '.' : inattendu dans la liste de paramètres de macro

I guess I shouldn’t use a Visual C based distribution which doesn’t understand the (args ...) syntax with #define. But Diskuv seems (now) to be the priviledged distribution for Windows. Will OCaml 5 + opam 2.2 will switch the C-toolchain ?

With opam install lablgtk, it is weirder :

=> This package requires gtk+ 2.0 development packages installed on your system.

However, the gtk+ -2.0 is well installed. pkg-config prints :
gtk+-2.0 GTK+ - GTK+ Graphical UI Library (win32 target).

DKML already comes with MSYS2. Access it with with-dkml bash.

In the interest of time, replace those commands with:

with-dkml pacman -S mingw-w64-clang-x86_64-gtk2 mingw-w64-clang-x86_64-pkg-config

which will download the CLANG64 ABI for GTK2 and pkg-config. But doubtful it will work since I doubt anyone has informed the package maintainer about your Windows issue.

So, in general, if you think a package should support Windows and you think there is an easy path to do so, file an issue with the package maintainer (lablgtk) and walk them through what steps are necessary. Since you have already mentioned it requires pacman, the “correct” answer is to wait until MSYS2 + Cygwin packages are fully supported in opam 2.2. But still, file an issue so the package maintainer knows there is interest on the Windows side.

Random aside: GTK2 is very old; there are GTK3 and GTK4.

1 Like

That probably does not help you: But on the Cygwin-based OCaml for Windows setup, lablgtk3 (depending on GTK3) works quite well. opam even installs the gtk3 dependencies automatically.