How to write a gtk-fortran application that can be used with or without GUI

I have created a new repository:

These gtk-fortran applications demonstrate how you can write an application that can work both with a GTK 4 graphical user interface (GUI) and as a simple command line executable. You can therefore enjoy your graphical application on your machine, and launch it on a machine where gtk-fortran is not installed, or launch it on a distant machine via an ssh connection. You may also want to run a long computation without its GUI to reach full speed, as there can be some performance impediment when you draw heavily on screen.

These examples are under MIT license (contrarily to the gtk-fortran repository which is under GPL), so you can begin working on your own gtk-fortran application without worrying about license problems. You can pick an app and adapt it to your own needs.

You will find two applications:

  • my_fast_app is computing and drawing a Lorenz attractor, in less than one second.
  • my_long_app is drawing a Buddhabrot in a few minutes. You need to manage the GUI main loop to keep it reactive.

More information in the README.md file of the project.

The screenshots can be seen here: Tutorial 3 · vmagnin/gtk-fortran Wiki · GitHub

7 Likes

Note that it is not a fpm project. I think it should be possible to use fpm using some tricks like a script renaming files or directories before launching fpm.

But the main problem I encounter is I failed to use commands like:

$ fpm --flag '$(pkg-config --cflags --libs gtk-4-fortran)' build

I tried also with " " and without ' '.

Updated: fpm 0.2.0 can not manage that, but the feature is ready for a future version. See Failed to build a simple gtk-fortran example: how to link with gtk-4-fortran? · Issue #487 · fortran-lang/fpm · GitHub

1 Like

Thanks! We should figure out how to use it as an fpm project. Does this work on a macOS also?

Regarding the license, I didn’t realize that GTK is under GPL (COPYING · master · GNOME / gtk · GitLab), if that is so, then I think since we are dynamically linking against the .so libraries, the main program also has to be GPL licensed. However this page suggests that the core C library uses LGPL: List of language bindings for GTK - Wikipedia, which allows to the wrappers to be licensed even under MIT, such as the Julia GTK wrappers. It would be nice to clarify this.

There are instructions to install gtk-3-fortran under macOS in the wiki: Home · vmagnin/gtk-fortran Wiki · GitHub
As GTK 4 seems to now be available in homebrew (gtk4 — Homebrew Formulae), it should be possible to install gtk-4-fortran and make those new examples work under macOS.

Concerning the license, I just know that since the beginning gtk-fortran is licensed under GNU General Public License version 3, with the additional permissions described in the GCC Runtime Library Exception version 3.1, which says:

When you use GCC to compile a program, GCC may combine portions of certain GCC header files and runtime libraries with the compiled program. The purpose of this Exception is to allow compilation of non-GPL (including proprietary) programs to use, in this way, the header files and runtime libraries covered by this Exception.

But I am not sure it is related to what you say about “dynamically linking against the .so libraries”. My brain is lost amongst technique, law and English… :face_with_thermometer:

1 Like

I think the exception that you mentioned covers this. It allows you to license your main program differently and still use GTK.

1 Like