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

9 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

2 Likes

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.

1 Like

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

When looking at the current LICENSE file in the gtk-fortran GitHub repository, there is a copy of GPL 3, but no reference to the GCC Runtime Library Exception.
So if I understand the LICENSE file provided with the GTK-Fortran sourcecode correctly, a program that uses GTK Fortran has to be provided to third parties with the GPL3 or a compatible license. This means, for example, that the entire code of the program has to be open source and free (as in speech, not in beer) software.

Is this assumption correct? Of course the developers of GTK Fortran are completely free to chose the license for their work and I do not really have an opinion about to what extent there should be exceptions from the GPL.
I just wanted to know if and to what extent the exception is still valid.
I am currently not planning to publish a Fortran GUI project, so I am not directly affected but I think such a clarification would be interesting for people considering the use of GTK Fortran in their projects.

1 Like

Thanks @Jweber for pointing this problem. The GCC Runtime Library Exception was chosen with the GPLv3 since the beginning of the project in 2011 (see for example Issue #24). And it is written in the header of the source files.

I will look how to fix the omission with @JerryD. I don’t know if we should copy the GCC Runtime Library Exception text into the LICENSE file, or if we should add a second file with that text.

(and I don’t think GitHub can handle that in its metada)

1 Like

That Wikipedia page helps understanding:

The Free Software Foundation states that, without applying the linking exception, a program linked to GPL library code may only be distributed under a GPL-compatible license.

1 Like

I have added a LICENSE_EXCEPTION file in the repository. The header of the source files were citing that exception and redirecting the users to Licenses - GNU Project - Free Software Foundation but it is a better practice to put the text of the license with the code, as demonstrated by your question.

I will still have to clarify the license in the conda-forge recipe.

Thanks again.

1 Like

Thanks a lot for the clarification!

I really think that for people/groups contemplating the use of a library for projects that are not purely internal, unambiguous license conditions can be quite important.

1 Like