Gtk-fortran 20.04 released, preparing for GTK 4

Daunting is the word! GTK is a huge API, a world in itself. I plan in the next months to add more tutorials. Up to now, the program examples were the only way to learn gtk-fortran. But I was inspired by this post: about documentation.

Regrettably, it is true there is very few books about GTK. In the Tutorials page, you will find those two books:

The first one is excellent, C oriented, but now obsolete (GTK 2). The second one is the GTK 3 version but for Python. Unhappily, I think it is easier to adapt C GTK code to Fortran than Python GTK code (higher level than the original).

For GTK 3, I recommend:
Michael B. has posted on its channel more than 200 videos on GTK 3 programming (C language)!

Having personally only tested gtk-fortran on Windows 7, have you encountered specific problems (not stated in the documentation) with Windows 10?

The only issue I found, but solved easily, was when doing make after cmake.
Make tried to compile a fortran source file with a line longer than 132 characters and GFortran (10.1) issued an error, not warning, thus stopping the build.
I just searched the culprit line and split it with an ampersand and voila.
I should mention that I did wget instead of pulling with git. I could check which file was later.

The examples I tried (julia, mandelbrot, and some more) were working fine.

1 Like

I could check which file was later.

I am interested to know the culprit. I have never encountered that error.

The examples I tried (julia, mandelbrot, and some more) were working fine.


Here is the error:

[ 89%] Building Fortran object sketcher/CMakeFiles/gtkf-sketcher.dir/gtkf-sketcher.out.f90.obj
f951.exe: Warning: Nonexistent include directory 'C:/Dev/msys64/mingw64/lib/libffi-3.2.1/include' [-Wmissing-include-dirs]

  596 |             call execute_command_line("python3 C:/Program Files (x86)/gtk-fortran/bin/gtk-3-fortran-pymodscan .", exitstat=shellout_err)
Error: Line truncated at (1) [-Werror=line-truncation]

  596 |             call execute_command_line("python3 C:/Program Files (x86)/gtk-fortran/bin/gtk-3-fortran-pymodscan .", exitstat=shellout_err)
Error: Syntax error in argument list at (1)

  878 |   use handlers
      |       1
Fatal Error: Cannot open module file 'handlers.mod' for reading at (1): No such file or directory
f951.exe: some warnings being treated as errors
compilation terminated.
make[2]: *** [sketcher/CMakeFiles/gtkf-sketcher.dir/build.make:83: sketcher/CMakeFiles/gtkf-sketcher.dir/gtkf-sketcher.out.f90.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:1518: sketcher/CMakeFiles/gtkf-sketcher.dir/all] Error 2
make: *** [Makefile:183: all] Error 2

After splitting the culprit line in /build/sketcher/gtkf-sketcher.out.f90 and doing make again it works fine.

1 Like

Thanks very much! That code was added this week. And the path to gtk-3-fortran-pymodscan is added by CMake. It is probably a little bit longer in Windows if you install in C:\Program Files (x86). I will work on that tomorrow.

Note also that I have recently added on the wiki:

  • Install the gtk-?-fortran library into your MSYS2 directory (by default CMake uses C:\Program Files (x86) but the spaces will cause problems with pkg-config):


That solution was found at

Hi @vmagnin, I just started with gtk-3-fortran. I followed the installation instructions, and everything was installed successfully and a couple of examples that I tested also run ok.
Just completed your first tutorial as well. Thank you for all the work you are doing there!

I only want to note a small detail and please correct me if I am wrong: gtk-3-fortran lib seems to be compiled with GNU Fortran v7.5.0? When tried your first tutorial I had to go backwards from 10 to 9, 8, and finally got it working with 7, by replacing in the command line gfortran with gfortran-7 (at least for my case that I have several versions installed).
example error:

~/Projects/GTK_Apps/tutorials/tutorial_1$ gfortran my_first_gtk_app.f90 $(pkg-config --cflags --libs gtk-3-fortran)

    3 |     use gtk, only: gtk_application_new, G_APPLICATION_FLAGS_NONE, &
      |         1
Fatal Error: Cannot read module file ‘/usr/local/include/gtk-3-fortran/gtk.mod’ opened at (1), because it was created by a different version of GNU Fortran
compilation terminated.

Nothing important, but if that is the case perhaps you could mention this at the beginning of the tutorials for new users like myself.

1 Like

Thanks @stavros for feedback!
Normally, it is CMake which detects the Fortran compiler of the system:

$ cmake ..
-- The Fortran compiler identification is GNU 9.2.1
-- Check for working Fortran compiler: /usr/bin/f95

On my Ubuntu system, I have gfortran 4.8, 5.5, 7.5, 8.5, 9.2. But the command gfortran corresponds to:

$ gfortran --version
GNU Fortran (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008

What are the versions printed by those two commands on your system? (and what is your system? It is an interesting problem that I have never encountered).

Note that you can choose which compiler who want to use with that command:

$ cmake -D CMAKE_Fortran_COMPILER:FILEPATH=which gfortran-9 ..

You are correct and I would expect the same thing… I have installed in my system all versions from 7.5 up to 10.1 with default the latest. I am using Mint 19.1, which is based on Ubuntu 18.04.

$ gfortran --version
GNU Fortran (Ubuntu 10.1.0-2ubuntu1~18.04) 10.1.0

I control the different versions through update-alternatives:

$ update-alternatives --config gfortran 
There are 4 choices for the alternative gfortran (providing /usr/bin/gfortran).

  Selection    Path                  Priority   Status
* 0            /usr/bin/gfortran-10   40        auto mode
  1            /usr/bin/gfortran-10   40        manual mode
  2            /usr/bin/gfortran-7    10        manual mode
  3            /usr/bin/gfortran-8    20        manual mode
  4            /usr/bin/gfortran-9    30        manual mode

however the cmake recognises 7.5 when I run it from within the project:

gtk-fortran/build$ cmake ..
-- Building gtk-3-fortran
-- GNUInstallDirs: /usr/local lib include bin share share/man
-- System: Linux 4.15.0-96-generic x86_64
-- Compiler: GNU 7.5.0 /usr/bin/f95
-- Build type is: release
-- Compilation flags: -pthread -O3 -mtune=native -march=native
-- Configuring done
-- Generating done
-- Build files have been written to:...

Any idea why?

1 Like

No, I never had that problem. But I do not use update-alternatives (thanks, I didn’t know that command).

It seems CMake have chosen the version with the lowest priority!

In my notes, I had noted that CMake uses f95, which is a link toward the default Fortran compiler:

$ f95 --version
GNU Fortran (Ubuntu 9.3.0-10ubuntu2) 9.3.0

Didn’t know about f95 but I just checked and there is no difference:

$ f95 --version
GNU Fortran (Ubuntu 10.1.0-2ubuntu1~18.04) 10.1.0
1 Like

Perhaps you could see on