-
Notifications
You must be signed in to change notification settings - Fork 46
Installation
Let's get started with gtk-fortran: this tutorial will guide you to install it on your system, with specific instructions for Linux, Windows, FreeBSD and macOS. It is based on the gtk4 branch, where the main developments are now made (the gtk3 branch can still receive bug fixes but is near its end of life).
You need:
- a modern Fortran compiler (Fortran 2008 standard), for example GFortran which is mainly used to develop gtk-fortran. See the Fortran-lang.org compilers page for other compilers.
- The GTK development files (in Ubuntu the package name is
libgtk-4-dev
), - A build system: either CMake (version>=3.7) and pkg-config (or
pkgconf
) to build and install the whole library, or the Fortran Package Manager fpm to use gtk-fortran as a dependency.
Remarks:
- If you want to build the PLplot examples, you need the PLplot development files (PLplot>=5.13) and the PLplot Cairo driver. If PLplot was not compiled with the Fortran compiler you use, you can not build those examples.
- A few programs in the project use the
g_get_os_info()
function introduced in GLib 2.64, but they are not essential and you can ignore them with$ make -i
if your GLib is older.
Note that if you are a Fortran Package Manager fpm user and don't want to use CMake, you can read the tutorial How to use fpm to build a gtk-fortran project.
If you have a github account, just clone the repository:
$ git clone [email protected]:vmagnin/gtk-fortran.git
else you can use git with https:
$ git clone https://github.com/vmagnin/gtk-fortran.git
or you can click in your browser on the Code tab (top left), then click on the Clone or download button on the right, then click on Download ZIP and extract the files in your home directory.
First, you need to install a Fortran compiler, the GTK development files, CMake and pkg-config. In a Debian based distribution like Ubuntu just type:
$ sudo apt install gfortran libgtk-4-dev cmake pkg-config
If you want to use PLplot in gtk-fortran:
$ sudo apt install libplplot-dev plplot-driver-cairo
Note that depending on your distribution, you may also need other packages and the names of the packages may be different.
You can then build and install gtk-fortran by typing:
$ cd gtk-fortran
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install
If PLplot is not installed on your machine or was not compiled with the same Fortran compiler, you must tell CMake to exclude the PLplot gtk-fortran examples before calling make
:
$ cmake -D EXCLUDE_PLPLOT=true ..
$ make
$ sudo make install
See CMake basics for other useful options and advices.
You can test gtk-fortran by running each example in the build/examples
and build/plplot
directories:
$ cd examples
$ ./gtkhello
or you can use CTest to launch and test all the examples sequentially (see CMake basics).
On Linux and Unix systems the build system generates a pkg-config file and installs it. So building a single source file application should be as simple as:
$ gfortran my_app.f90 $(pkg-config --cflags --libs gtk-4-fortran)
If you use PLplot, don't forget to add its packages in the pkg-config
command:
$ gfortran my_plplot_app.f90 $(pkg-config --cflags --libs gtk-4-fortran plplot plplot-fortran)
If you have made a default install to /usr/local
you may need to run:
$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
or
$ setenv PKG_CONFIG_PATH /usr/local/lib/pkgconfig
if you use csh or one of its derivatives.
This will depend on your distribution, Ubuntu looks there by default, Pardus and Manjaro don't. Just look the messages of the sudo make install
command to know that directory, for example in Ubuntu you will find that line:
-- Installing: /usr/local/lib/pkgconfig/gtk-4-fortran.pc
In Fedora it's /usr/local/lib64/pkgconfig
.
A first solution is to use WSL: in that user post, you will find some information on how to use gtk-fortran in a WSL2 Ubuntu installation and how to configure MS Visual Studio Code.
Another solution is to use MSYS2-MINGW64:
- Download, install and update it as explained on the site MSYS2
- Install the following packages via the MSYS2-MSYS shell:
- build tools:
$ pacman -S mingw-w64-x86_64-toolchain base-devel
- cmake and git:
$ pacman -S mingw-w64-x86_64-cmake git
(it will also install openssh and vim) - GTK and dependencies: `$ pacman -S mingw-w64-x86_64-gtk4
- PLplot:
$ pacman -S mingw-w64-x86_64-plplot mingw-w64-x86_64-qhull mingw-w64-x86_64-libgd
(optional)
- build tools:
- Your MSYS2 directory size will be around 2 Gio.
- Start the MSYS2-MINGW64 shell.
- Install gtk-fortran either with git:
$ mkdir .ssh
- Copy your key
id_rsa
in the.ssh
directory. $ git clone [email protected]:vmagnin/gtk-fortran.git
$ cd gtk-fortran
- or by downloading and extracting the .tar.gz:
$ wget https://github.com/vmagnin/gtk-fortran/archive/gtk4.tar.gz
$ tar -xvzf gtk4.tar.gz
$ cd gtk-fortran-gtk4
- Create a
build
directory:$ mkdir build && cd build
- Generate make files with:
$ cmake -G "MSYS Makefiles" ..
- The reason is the default on MSYS or MINGW is "NMake Makefiles".
-
$ make -j
(in MSYS2, the building can be several times slower than under Linux.make -j
for parallel building will accelerate it). - Test the examples like described in the Linux section.
- 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):
$ MSYS2_ARG_CONV_EXCL=- cmake . -G"MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=$MINGW_PREFIX
$ make -j install DESTDIR=/
That solution was found at https://stackoverflow.com/questions/44282788/cmake-msys2-wrong-install-path-for-library
See this blog if you want to use gtk-fortran and Code::Blocks in Windows.
You need the Homebrew package manager.
Follow those steps (see https://github.com/vmagnin/gtk-fortran/issues/154) where you will adapt the ln
command to you gcc version:
$ brew install gcc
$ ln -s /usr/local/Cellar/gcc@7/7.5.0/bin/gfortran-7 /usr/local/bin/gfortran
$ brew install gtk4
Download gtk-fortran as explained for Linux and open a terminal in the source directory. Then export the pkg-config path
and build gtk-fortran:
$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
$ mkdir build && cd build
$ cmake -D EXCLUDE_PLPLOT=true ..
$ make
$ sudo make install
You may also need:
$ export LIBRARY_PATH=/usr/local/lib/
You need to download the sources (see the FreeBSD section) then build PLplot so that it has been built with the same version of gfortran. The PLD_xcairo
setting needs to be off:
$ mkdir build && cd build
$ cmake -D PLD_xcairo=OFF ..
$ make
$ sudo make install
Install the packages:
# pkg install git cmake pkgconf gcc11 gtk4
After cloning the gtk-fortran directory:
$ cd gtk-fortran
$ mkdir build && cd build
$ cmake -D EXCLUDE_PLPLOT=true -D CMAKE_Fortran_COMPILER:FILEPATH="/usr/local/bin/gfortran11" ..
$ make
$ cd examples
$ ./gtkhello
The environment variable LD_PRELOAD
is necessary if you have an error concerning ligcc_s.so.1
:
$ export LD_PRELOAD=/usr/local/lib/gcc11/libgcc_s.so.1
FreeBSD lacks the plplot-fortran
package. But you can install PLplot from sources using CMake:
$ wget https://downloads.sourceforge.net/project/plplot/plplot/5.15.0 Source/plplot-5.15.0.tar.gz
$ tar -xf plplot-5.15.0.tar.gz
$ mkdir build_plplot && cd build_plplot
$ export FC=/usr/local/bin/gfortran11
$ cmake -D CMAKE_INSTALL_PREFIX=/home/osboxes/myPLplot ../plplot-5.15.0
$ make
$ sudo make install
and then in your gtk-fortran build directory:
$ PKG_CONFIG_PATH=/home/osboxes/myPLplot/lib/pkgconfig cmake ..
It will generally be as easy as typing from the build directory:
$ sudo make uninstall
Another solution is to remove by hand the files listed in build/install_manifest.txt
See https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
- 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