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.


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.

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:

You may also be interested by:
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:
and for help:

But it is also more simply available in conda-forge: