# How to use gtk-fortran?

**URL:** <https://fortran-lang.discourse.group/t/how-to-use-gtk-fortran/3762>\
**Category:** Help\
**Created:** [June 15, 2022, 7:17pm UTC](https://fortran-lang.discourse.group/t/how-to-use-gtk-fortran/3762 "2022-06-15T19:17:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakanott](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rakanott](https://fortran-lang.discourse.group/u/rakanott)\
**Post date:** [June 15, 2022, 7:17pm UTC](https://fortran-lang.discourse.group/t/how-to-use-gtk-fortran/3762/1 "2022-06-15T19:17:03Z")

</div>

I really needed to have some sort of graphical representation of my fortran code, and i eventually discovered fortran gtk, but i had really hard time figuring it out. There’s not a lot of videos or info about this that i can use, so maybe someone here has something to say? Like how to connect gtk to my fortran project, because even when im trying to launch examplex from gtk’s github it all falls flat, because code refuses to see 1-2 packages with either .mod or .f90 extension. Does anyone have any ideas about this? Thanks.

---

<div class="post-metadata">

**Author:** ![alozada](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/alozada/32/298_2.png) [@alozada](https://fortran-lang.discourse.group/u/alozada)\
**Post date:** [June 15, 2022, 7:20pm UTC](https://fortran-lang.discourse.group/t/how-to-use-gtk-fortran/3762/2 "2022-06-15T19:20:09Z")

</div>

> **[Tutorial 1 · vmagnin/gtk-fortran Wiki](https://github.com/vmagnin/gtk-fortran/wiki/Tutorial-1)**
>
> A GTK / Fortran binding. Contribute to vmagnin/gtk-fortran development by creating an account on GitHub.

@vmagnin

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [June 15, 2022, 7:21pm UTC](https://fortran-lang.discourse.group/t/how-to-use-gtk-fortran/3762/3 "2022-06-15T19:21:57Z")

</div>

Can you give more details: gtk-fortran branch, OS?  
And a copy of the errors in your terminal.

My advice is, if possible, that you use the gtk4 branch. I still loosely maintain the gtk3 branch but only for bugs. All new developments are for GTK 4.

If you have difficulties with CMake, you can now use gtk-fortran as a fpm dependency.

---

<div class="post-metadata">

**Author:** ![rakanott](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rakanott](https://fortran-lang.discourse.group/u/rakanott)\
**Post date:** [June 15, 2022, 7:22pm UTC](https://fortran-lang.discourse.group/t/how-to-use-gtk-fortran/3762/4 "2022-06-15T19:22:53Z")

</div>

This is pretty useful, but sadly i have problem with actually connecting gtk to my project. Once this will be fixed, though, i will definately explore this tutorial!

---

<div class="post-metadata">

**Author:** ![rakanott](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rakanott](https://fortran-lang.discourse.group/u/rakanott)\
**Post date:** [June 15, 2022, 7:28pm UTC](https://fortran-lang.discourse.group/t/how-to-use-gtk-fortran/3762/5 "2022-06-15T19:28:33Z")

</div>

Yes. My OC is Windows 10, and the problem seems trivial enough. I just can’t properly connect gtk to my fortran project, since for some reason i can’t use “git” command in my terminal, while having github installed, and there’s essentially no(at least i haven’t managed to find any) tutorials that involve directly interacting with zip that i can download from your gitHub page. Also i don’t really wanna use fpm, since it’s only for Visual studio 2019, but if nothing will work i will have to use that i think.  
 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/c/c23dc03b2fe0802cb3789a2db3f2a7e22d946272.png)

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [June 15, 2022, 7:38pm UTC](https://fortran-lang.discourse.group/t/how-to-use-gtk-fortran/3762/6 "2022-06-15T19:38:19Z")

</div>

You can use git clone or download a zip. Then you should use CMake to build the whole project. If you use MSYS2 under Windows, the instructions are here:  
[https://github.com/vmagnin/gtk-fortran/wiki/Installation#windows](https://github.com/vmagnin/gtk-fortran/wiki/Installation#windows)

You may also be interested by:  
[https://github.com/vmagnin/gtk-fortran/wiki/Alternatives-to-CMake#direct-compilation](https://github.com/vmagnin/gtk-fortran/wiki/Alternatives-to-CMake#direct-compilation)  
If you know what modules are needed for each example, you can compile them directly with the example. For example, under Linux, to build and run the julia\_pixbuf.f90 example I would type (from the `src/` directory):

```bash
$ gfortran glib-auto.f90 cairo-auto.f90 gdk-auto.f90 gdk-pixbuf-auto.f90 gtk.f90 ../examples/julia_pixbuf.f90 $(pkg-config --cflags --libs gtk4)
$ ./a.out

```

---

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [June 16, 2022, 9:43am UTC](https://fortran-lang.discourse.group/t/how-to-use-gtk-fortran/3762/7 "2022-06-16T09:43:28Z")

</div>

> [@vmagnin](#):
>
> My advice is, if possible, that you use the gtk4 branch. I still loosely maintain the gtk3 branch but only for bugs. All new developments are for GTK 4.

Do you build GTK-4 on Linux from sources? I’ve checked a few modern distros - Ubuntu 20.04, Rocky Linux 8.6, MX-21 (Debian 11) - all of these seem to provide GTK-3 only.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [June 16, 2022, 9:57am UTC](https://fortran-lang.discourse.group/t/how-to-use-gtk-fortran/3762/8 "2022-06-16T09:57:35Z")

</div>

No, I am using latest Ubuntu and Fedora which ship with GTK 4. As far as I remember, GTK 4 was introduced in Ubuntu 21.10.

For building GTK 4 (with Meson), see: [https://docs.gtk.org/gtk4/building.html](https://docs.gtk.org/gtk4/building.html)  
and for help: [https://discourse.gnome.org/c/platform/5](https://discourse.gnome.org/c/platform/5)

But it is also more simply available in conda-forge:  
[https://anaconda.org/conda-forge/gtk4](https://anaconda.org/conda-forge/gtk4)  
[https://anaconda.org/conda-forge/gtk-4-fortran](https://anaconda.org/conda-forge/gtk-4-fortran)
