Trying to get Gtk-Fortran to work in VS2019 with Intel Fortran Compiler

Huge thanks to vmagnin for their help on this. Below is my documented steps on how I finally managed to solve this problem. Posting this in hopes that on the off chance anyone else tries to do this without any prior knowledge of any of these things, this will be helpful to them. (had to modify because of 2 link limit)

Need to have Visual Studio 2019 installed and Intel Fortran Compiler added before doing any of these things, steps not noted here since this is done by our sys admin/IT staff.

Install GIT for Windows

Link: gitforwindows dot org

  • Install the executable
  • Recommend switching to Notepad++ as the default editor when prompted
  • Recommend switching to “Checkout as-is, commit as-is” on line ending conversions prompt
  • Otherwise, just stick with default options unless you know you need something else

Install MSYS2

Link: msys2 dot org

  • Install the executable following defaults (C:\msys64)
  • Run “MSYS2 MSYS” from start menu
  • Run “pacman –Syu”, at the end of this process, it will prompt you to close the program/prompt to finish installation, choose Yes
  • Run “MSYS2 MSYS” from start menu again
  • Run “pacman –Su”, wait for it to finish, will take a while
  • Run “pacman –S –needed base-devel mingw-w64-x86_64-toolchain”

Install Python 3.6.x

Link: python dot org/ftp/python/3.6.2/python-3.6.2-amd64.exe

  • Download and run executable from above link
  • Choose Custom Installation
  • On “Optional Features” page, make sure everything is checked that can be
  • On “Advanced Options” page, make sure everything is checked that can be, change the “Customize install location” path to “C:\Python36”
  • Install
  • At the end, you will get a “Setup was successful” page, make sure to hit the button to “Disable path length limit”
  • Close installer

Building the GTK3 Libraries on Windows 10, Visual Studio 2019

Guide: github dot com/wingtk/gvsbuild

  • Create the directories to a path “C:\gtk-build\github”
  • Open a command prompt window (Winkey+R, type “cmd”, hit enter; or start typing “command” at start menu)
  • Run “cd C:\gtk-build\github”
  • Run “git clone https://github.com/wingtk/gvsbuild”
  • Run “cd gvsbuild”
  • Run “python build.py build –p x64 --vs-ver 16 gtk3”
    • This will run a python script, specifying 64-bit build, and Visual Studio version 16 (2019), build the gtk3 library. This took ~15 minutes on a company laptop, so be patient.

Setting up a Static Library project for GTK-Fortran in Visual Studio

Link: github dot com/vmagnin/gtk-fortran/tree/gtk3

  • First, get a copy of the GTK-Fortran library from the link above. This can be done from command prompt by making a directory somewhere, cd’ing to that directory, then typing “git clone https://github.com/vmagnin/gtk-fortran/tree/gtk3”, or by going to the website, clicking on the green Code button at the top right, and selecting “Download ZIP”.
  • Open Visual Studio 2019, select “Create New Project”, use the drop-downs to filter Languages to Fortran and Project Types to Library, then select “Static Library” and hit next. Name your project and put it in your desired directory, then hit Create. (Take note of where your project is being stored, you will need to add this project to your main solution later)
  • In a windows explorer window, navigate to the directory where you downloaded/unzipped the GTK-Fortran library. Look under the “src” folder, sort by file type, and select all of the *.f90 files in this directory. Drag all of these files into the Visual Studio window onto the “Source Files” folder. You should now be able to expand the “Source Files” folder in the Visual Studio Solution Explorer and see all of the *.f90 files.
  • Update the build settings from “Debug” and “x86” at the top of Visual Studio to “Release” and “x64”
  • Build the solution (Ctrl+Shift+B, Build->Build Solution, or Start button)

Setting up your working GUI project in Visual Studio

  • Open Visual Studio 2019, select “Create New Project”, use the drop-downs to filter Languages to Fortran, then select “Empty Project” and hit next. Name your project and put it in your desired directory, then hit Create. (Take note of where your project is being stored, you will need to move files there later)
  • In the Solution Explorer, right click on your Solution (should be top item), select Add->Existing Project… Navigate to the Static Library project file that you created above (*.vfproj) and hit okay
  • Your solution should now contain both the project you just created as well as the static library project in the Solution Explorer.
  • In the Solution Explorer, right click on your project (not the static library), select Build Dependencies->Project Dependencies… In the window that opens, under the list of “Depends On:”, check the checkbox next to the name of your static library project, then hit OK.
  • Add or create your source code file, adding it to the current project under Source Files.
  • Open a windows explorer window and navigate to “C:\gtk-build\gtk\x64\release\lib”, sort the folder by file type, select all of the *.lib files, drag them into your new project in Visual Studio under Source Files
  • Optional, but recommended, create a sub-folder under Source Files and put all of the *.lib files in that folder instead/first
  • Ensure that this project is also set to “Release” and “x64” settings at the top
  • Build your solution, should in theory get no errors if code is bug free, but still won’t open as executable at this point
  • Open a windows explorer window and navigate to the folder containing your solution, then dig down into “<Project Name>\x64\Release” folder.
  • Open a separate windows explorer window and navigate to “C:\gtk-build\gtk\x64\release\bin”, sort folder by file type, and copy all of the *.dll files from this folder over into the Release folder of your project (one step up)
  • You should now be able to run your .exe program from the Release folder

It cannot be stressed enough:

  • Both the static library and the final project both have to be set to “Release” and “x64”
  • The version of GTK must match between the C based GTK libraries and the Fortran based GTK-Fortran libraries. At the time of writing, GTK4 is available, but the tools to build it are not updated yet, so this set of instructions is for building GTK3 ONLY .
4 Likes

Thanks for posting this detailed how-to. I will put a link in the gtk-fortran wiki page as soon as possible.

1 Like