-
Notifications
You must be signed in to change notification settings - Fork 46
Tutorial 5
We demonstrate how the Fortran Package Manager fpm can be used to build and run a gtk-fortran program, starting from the gtkzero_gapp.f90 example, which just opens an empty GTK 4 window. The source of the resulting fpm project is available in the following repository:
https://github.com/vmagnin/gtkzero_fpm
-
gtk-fortran
is supposed to be installed in your system (withsudo make install
on a Unix-like system), following instructions on the main wiki page. - A Fortran Package Manager fpm >=0.3.0 is also supposed to be installed.
An hello world project is first created by:
$ fpm new gtkzero_fpm
$ cd gtkzero_fpm
The gtkzero_gapp.f90
file is just composed of the main Fortran program and a module named handlers
. In the fpm version, we put the main program into the app/main.f90
file and the module into src/handlers.f90
(the file must have the name of the module).
The tree of the project is:
├── app
│ └── main.f90
├── build
├── fpm.toml
├── README.md
├── src
│ └── handlers.f90
└── test
└── check.f90
As our program uses the gtk
and g
(for GLib) gtk-fortran modules, the fpm.toml
manifest must contain:
[build]
external-modules = ["gtk", "g"]
Let's have a look at the flags returned by pkg-config
:
$ pkg-config --cflags --libs gtk-4-fortran
-rdynamic -mfpmath=sse -msse -msse2 -pthread -I/usr/local/include/gtk-4-fortran -I/usr/include/gtk-4.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/graphene-1.0 -I/usr/lib/x86_64-linux-gnu/graphene-1.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Xlinker -R/usr/local/lib -lgtk-4-fortran -lgtk-4 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lvulkan -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
The --cflags
option returns flags for the compiler, the second option --libs
returns options for the linker:
$ pkg-config --libs gtk-4-fortran
-Xlinker -R/usr/local/lib -lgtk-4-fortran -lgtk-4 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lvulkan -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
We will keep the first two options -Xlinker -R/usr/local/lib
in our command line but will put the names of the libraries to be linked in the build section of the fpm.toml
file:
[build]
link = [
"gtk-4",
"pangocairo-1.0",
"pango-1.0",
"harfbuzz",
"gdk_pixbuf-2.0",
"cairo-gobject",
"cairo",
"vulkan",
"graphene-1.0",
"gio-2.0",
"gobject-2.0",
"glib-2.0",
"gtk-4-fortran" ]
external-modules = ["gtk", "g"]
The project can now be built and run with the command:
$ fpm run --flag '$(pkg-config --cflags gtk-4-fortran) -Xlinker -R/usr/local/lib'
That's all folks!
- If you first build the project with
fpm build --flag '$(pkg-config --cflags gtk-4-fortran) -Xlinker -R/usr/local/lib'
, you will be obliged to launchfpm run
with the same flags, because each fpm build is identified by a hash of the command line arguments. - In the
[build]
section, we have listed all the libraries composing GTK, but for that small example we only really need:
link = [
"gtk-4",
"gio-2.0",
"gobject-2.0",
"glib-2.0",
"gtk-4-fortran",
]
- For the moment, gtk-fortran itself can not be built using fpm, or used as a fpm dependency. See https://github.com/vmagnin/gtk-fortran/discussions/246
- 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 with other C libraries