-
Notifications
You must be signed in to change notification settings - Fork 43
Tutorial 5
In this tutorial, you will transform the most simple gtk-fortran example (it just opens an empty GTK window) into a Fortran Package Manager fpm project. The source of the resulting fpm project is available in the gtkzero_fpm repository.
I suppose you have already installed:
- gtk-fortran >= 4.2 (or >=3.24.41).
- The Fortran Package Manager fpm.
- GTK 4 (or GTK 3) and its development files.
- The git version control system.
You will first create a "hello world" fpm project named gtkzero_fpm
:
$ fpm new gtkzero_fpm
$ cd gtkzero_fpm
The tree of the project created by fpm is:
├── app
│ └── main.f90
├── build
├── fpm.toml
├── README.md
├── src
│ └── handlers.f90
└── test
└── check.f90
Now open the examples/gtkzero_gapp.f90 gtk-fortran example in your text editor. That file just contains the main Fortran program and a module named handlers
. Copy the main program into the app/main.f90
file and the module into src/handlers.f90
(although it is a good practice to use the same name for the file and the module, don't care about that now).
The fpm.toml
manifest must contain a dependencies section with the needed branch of gtk-fortran. Open the manifest in your editor and add those two lines:
[dependencies]
gtk-fortran = { git = "https://github.com/vmagnin/gtk-fortran.git", branch = "gtk4" }
(or branch = "gtk3"
)
Now you can build and run the project very simply thanks to fpm:
$ fpm run
After having automatically cloned gtk-fortran in the build/dependencies/
directory of the project, fpm will build everything and run the executable. You should see on screen an empty GTK window with an "hello world" title:
That's all folks! You have successfully created your first gtk-fortran fpm project.
Let's just finish with two useful remarks:
If you have several projects using gtk-fortran, it would be a better solution to clone the gtk-fortran repository alongside your projects and replace in their fpm.toml
manifests the git dependency by the local path to gtk-fortran:
[dependencies]
gtk-fortran = { path = "../gtk-fortran" }
If your fpm project also uses the PLplot features of gtk-fortran, you need to add in the fpm.toml
manifest:
[build]
link = ["plplot", "plplotfortran"]
external-modules = ["plplot"]
and you will build and run it with:
$ fpm run --flag '$(pkg-config --cflags --libs plplot plplot-fortran)'
- Installation
- My first gtk-fortran application
- Drawing an image in a PNG file (without GUI)
- A program also usable without GUI
- Using Glade3 and gtkf-sketcher (GTK 3)
- Using gtk-fortran as a fpm dependency
- Debugging with GtkInspector
- Learning from examples
- Video tutorials
- How to start my own project from a gtk-fortran example
- git basics
- CMake basics
- Alternatives to CMake
- How to migrate to GTK 4
- How to contribute to gtk-fortran
- How to hack the cfwrapper