How to use gtk-fortran?

I really needed to have some sort of graphical representation of my fortran code, and i eventually discovered fortran gtk, but i had really hard time figuring it out. There’s not a lot of videos or info about this that i can use, so maybe someone here has something to say? Like how to connect gtk to my fortran project, because even when im trying to launch examplex from gtk’s github it all falls flat, because code refuses to see 1-2 packages with either .mod or .f90 extension. Does anyone have any ideas about this? Thanks.

@vmagnin

1 Like

Can you give more details: gtk-fortran branch, OS?
And a copy of the errors in your terminal.

My advice is, if possible, that you use the gtk4 branch. I still loosely maintain the gtk3 branch but only for bugs. All new developments are for GTK 4.

If you have difficulties with CMake, you can now use gtk-fortran as a fpm dependency.

This is pretty useful, but sadly i have problem with actually connecting gtk to my project. Once this will be fixed, though, i will definately explore this tutorial!

Yes. My OC is Windows 10, and the problem seems trivial enough. I just can’t properly connect gtk to my fortran project, since for some reason i can’t use “git” command in my terminal, while having github installed, and there’s essentially no(at least i haven’t managed to find any) tutorials that involve directly interacting with zip that i can download from your gitHub page. Also i don’t really wanna use fpm, since it’s only for Visual studio 2019, but if nothing will work i will have to use that i think.
image

You can use git clone or download a zip. Then you should use CMake to build the whole project. If you use MSYS2 under Windows, the instructions are here:
https://github.com/vmagnin/gtk-fortran/wiki/Installation#windows

You may also be interested by:
https://github.com/vmagnin/gtk-fortran/wiki/Alternatives-to-CMake#direct-compilation
If you know what modules are needed for each example, you can compile them directly with the example. For example, under Linux, to build and run the julia_pixbuf.f90 example I would type (from the src/ directory):

$ gfortran glib-auto.f90 cairo-auto.f90 gdk-auto.f90 gdk-pixbuf-auto.f90 gtk.f90 ../examples/julia_pixbuf.f90 $(pkg-config --cflags --libs gtk4)
$ ./a.out

Do you build GTK-4 on Linux from sources? I’ve checked a few modern distros - Ubuntu 20.04, Rocky Linux 8.6, MX-21 (Debian 11) - all of these seem to provide GTK-3 only.

No, I am using latest Ubuntu and Fedora which ship with GTK 4. As far as I remember, GTK 4 was introduced in Ubuntu 21.10.

For building GTK 4 (with Meson), see: https://docs.gtk.org/gtk4/building.html
and for help: https://discourse.gnome.org/c/platform/5

But it is also more simply available in conda-forge:
https://anaconda.org/conda-forge/gtk4
https://anaconda.org/conda-forge/gtk-4-fortran