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

Hey, thanks for having me :slight_smile: I was actually referred here from reddit as people said I should ask here since you (the dev of gtk-fortran) frequents this forum.

So, I copied over my compiled/built folders of gtk-fortran that were compiled using MSYS2-MINGW64 (following the guide on the github step by step). When I include just the dll file(s) in the project in VS2019, I get errors saying that it can’t find the libraries (error at ‘use gtk’). When I include the modules directory (all the .mod files), it says that it can’t use the mod files because they weren’t compiled with the Intel Fortran Compiler.

I guess what I need more than anything is a step-by-step guide of how to (re)compile/build/make the mod files and dll files using the Intel Fortran Compiler. After that it should be off to the races, at least in theory.

I can copy over exact error messages I am getting if needed, but the project is on an air-gapped computer so I would have to transpose it manually (the only reason I haven’t already).

Hope that’s better info to go off of. Sorry for being a total newbie on this stuff. I mostly work in C# and MATLAB, so this is way out of my wheelhouse.

Don’t be sorry, the Discourse is for everyone from beginner to expert! Everyone is welcome and has something to bring.

Concerning the .mod files, yes they are compiler dependent:
http://fortranwiki.org/fortran/show/Compiler+.MOD+files

Perhaps a first step would be to try to call the Intel Fortran compiler from the MSYS2 command line, with a command that will approximately be:

$ cmake -G "MSYS Makefiles" -D CMAKE_Fortran_COMPILER:FILEPATH="C://'Program Files/Intel/ifort.exe'" ..

after having corrected the path with the real one (I have not that compiler installed, so I don’t know)!
Note the double slash. I have successfully launched a Windows .exe from MSYS2 like that:

$ C://'Program Files/PuTTy/putty.exe'

Hey vmagnin,

I know this was months ago, but work just now finally got me a machine where I can both have the Intel Fortran Compiler and the ability to install my own software (MSYS2) to be able to test your suggestion above.

Unfortunately, it is giving me lots of errors when trying to specify ifort.exe as the ‘CMAKE_Fortran_COMPILER’ argument.
The command I am using, specifically, is:

cmake -G “MSYS Makefiles” -D CMAKE_Fortran_COMPILER:FILEPATH=“C://Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/intel64/ifort.exe” …

The error log file contains thousands of lines that read something like "C:/msys64/mingw64/share/cmake-3.20/Modules/CMakeFortranCompilerABI.F(5): warning #5117: Bad # preprocessor line

#if defined(_LP64)

-^"

And then the following block of errors after that:

C:/msys64/mingw64/share/cmake-3.20/Modules/CMakeFortranCompilerABI.F(5): warning #5117: Bad # preprocessor line

#if defined(_LP64)

-^

The command line (MSYS2 console) also gives different errors:

The Fortran compiler

"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/intel64/ifort.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: C:/msys64/home/derek/gtk-fortran-gtk4/build/CMakeFiles/CMakeTmp

Run Build Command(s):C:/msys64/usr/bin/make.exe -f Makefile cmTC_27ee9/fast && /usr/bin/make  -f CMakeFiles/cmTC_27ee9.dir/build.make CMakeFiles/cmTC_27ee9.dir/build
make[1]: Entering directory '/home/derek/gtk-fortran-gtk4/build/CMakeFiles/CMakeTmp'
Building Fortran object CMakeFiles/cmTC_27ee9.dir/testFortranCompiler.f.obj
"/C/Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/intel64/ifort.exe"    -c /C/msys64/home/derek/gtk-fortran-gtk4/build/CMakeFiles/CMakeTmp/testFortranCompiler.f -o CMakeFiles/cmTC_27ee9.dir/testFortranCompiler.f.obj
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.1.216 Build 20200306
Copyright (C) 1985-2020 Intel Corporation.  All rights reserved.

Linking Fortran executable cmTC_27ee9.exe
"/C/Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/intel64/ifort.exe" "CMakeFiles/cmTC_27ee9.dir/testFortranCompiler.f.obj"  -o cmTC_27ee9.exe
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.1.216 Build 20200306
Copyright (C) 1985-2020 Intel Corporation.  All rights reserved.

link: unknown option -- s
Try 'link --help' for more information.
make[1]: *** [CMakeFiles/cmTC_27ee9.dir/build.make:98: cmTC_27ee9.exe] Error 1
make[1]: Leaving directory '/home/derek/gtk-fortran-gtk4/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:127: cmTC_27ee9/fast] Error 2

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:38 (project)

– Configuring incomplete, errors occurred!

Any thoughts?

Can you try adding apostrophes around the path?

“C://'Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/intel64/ifort.exe'”

I used them in the examples in my previous messages, probably because of the space in the middle of the directory name (Program Files).

In fact, before trying to use it with CMake, the first thing to do is to verify that you can access ifort from the MSYS2/MINGW terminal, by just typing (without the $ of course):

$ C://'Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/intel64/ifort.exe'

You should obtain that kind of message (supposing it’s the same message than in Linux):

ifort: command line error: no files specified; for help type "ifort -help"

So, when I try typing in just the path to ifort.exe without the cmake command, it returns the error message that you said it should of no files specified.

When I try adding single quotes around the path portion of the cmake command, it returns:
$ cmake -G “MSYS Makefiles” -D CMAKE_Fortran_COMPILER:FILEPATH=“C://‘Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/intel64/ifort.exe’” …
– The Fortran compiler identification is unknown
CMake Error at CMakeLists.txt:38 (project):
The CMAKE_Fortran_COMPILER:

C:/'Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/intel64/ifort.exe'

is not a full path to an existing compiler tool.

Tell CMake where to find the compiler by setting either the environment
variable “FC” or the CMake cache entry CMAKE_Fortran_COMPILER to the full
path to the compiler, or to the compiler name if it is in the PATH.

I had tried the command with the single quotes as you specified first, but it gave me this, which I took to mean that my path wasn’t valid, so I tried it without and it gave me the other errors that I posted above, which sounded to me like it found the compiler but ran into errors.

I think you are right, I obtain the same error message if I give CMake a bad path under Linux.

In your error message, two things may be interesting:

CMakeFortranCompilerABI.F

and

link: unknown option -- s
Try 'link --help' for more information.
make[1]: *** [CMakeFiles/cmTC_27ee9.dir/build.make:98: cmTC_27ee9.exe] Error 1

As CMake was unable to detect correctly the compiler, it tried to compile a testFortranCompiler.f test file. It seems the .obj was correctly generated. But the linking stage failed. Is it because we try to mix Windows and Linux things?

There is a CMake option to change the linker: -D CMAKE_LINKER=/path/to/linker, see:
https://stackoverflow.com/questions/1867745/cmake-use-a-custom-linker
Maybe you should look in that direction…

Is it because we try to mix Windows and Linux things?
Probably…

I can try to start looking into changing the linker. Would the Intel Fortran Compiler have it’s own linker, or would it be using Visual Studio’s linker?

Also, is there any way to compile the Gtk-Fortran libraries using the Intel Fortran Compiler directly? What would someone use in place of cmake?

Thanks again for all the help!

Concerning linkers, I am not competent.

In the project, there is a script src/alt_build_test.sh to build the library and the examples : git pull the latest commits, as I have just updated that script in the gtk3 & gtk4 branches, on the 11th June. I have tested it successfully under MSYS2 (with the MSYS2 gfortran).

You may try to use it with ifort.exe.
The command under Linux is:

$ FC="ifort" ./alt_build_test.sh

Under MSYS2, you can try:

$ FC="C://Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/intel64/ifort.exe" ./alt_build_test.sh

(add apostrophes if needed…)

You may also read:
https://github.com/vmagnin/gtk-fortran/wiki/Alternatives-to-CMake

And if you know which gtk-fortran files are needed, you can also simply compile and run each example as follow, from the src/ directory :
$ gfortran glib-auto.f90 cairo-auto.f90 gdk-auto.f90 gdk-pixbuf-auto.f90 gtk.f90 ../examples/julia_pixbuf.f90 $(pkg-config --cflags --libs gtk+-3.0)

For GTK 4, it’s --libs gtk4

I tried using Cygwin (no clue why I wrote Putty here initially…) to emulate running shell script on Windows, but still was unable to make any progress going this route. ifort unfortunately is not gfortran or msys2, and it just seems to be incompatible in ways I can’t understand.

I tried a different approach of importing all of the .f90 source files from the gtk-fortran library into a new Visual Studio project and tried to compile the code using the Intel Fortran Compiler, and it seems to run to a point, then it starts spitting out errors that look like this:

error LNK2019: unresolved external symbol _gdk_pixbuf_get_rowstride referenced in function _GDK_PIXBUF_HL_mp_HL_GDK_PIXBUF_INFO||gdk-pixbuf-hl.obj|||

I get 360 such errors that all appear to follow this format. Is it missing other libraries/dependencies that are located inside of the gfortran and/or msys2 compilers? Could I pull those into the project to give it knowledge of what it’s looking for?

Again, thanks for all of your help and sorry for being so out of my depth on these things.

Putty is a SSH client, that you will use to connect to a distant machine. It does not emulate a Linux terminal on your machine.

When somebody talks about GTK, be conscious that GTK can mean the GTK library itself (with all the GUI widgets) but also the collection of libraries: GTK is just one of those libraries, but there is also GLib (on which is based GTK), Pango, Cairo, gdk-pixbuf… The error you shown is a linking error with the gdk-pixbuf library (which is used to draw pixels in an image).

When you compile a gtk-fortran program, you write something like:

$ gfortran my_app.f90 $(pkg-config --cflags --libs gtk-4-fortran)

But the pkg-config command expands like this:

`$ 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
`
Some may not be needed for gtk-fortran, but you will need GTK, GLib, gdk-pixbuf, Cairo, Pango, and a few others.

Sorry, I am not familiar with Visual Studio. And uses Windows only occasionally now… But you need to give Visual Studio access to all those needed libraries.

Note also that I remember that at the beginning of the gtk-fortran project, ten years ago, I had successfully compiled and run the examples using the gfortran Windows version and linking to the DLLs of the GTK libraries. And it was some dirty trick: I think I copied the DLL from the Gimp application (the original GTK was Gimp ToolKit) and put them in the same directory as the gtk-fortran examples. But it worked…

Maybe you should have a look at:
https://anadoxin.org/blog/bringing-visual-studio-compiler-into-msys2-environment.html/

Jumping back here, I pulled the latest version of the alt_build_test.sh script from your github and tried to run that in MSYS2 as you described here.

My output is as follows:

First it says:

$ FC=“C://Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/intel64/ifort.exe” ./alt_build_test.sh
Building gtk-4-fortran
Removing old files…
Compiling the GTK+ libraries and gtk_hl using C://Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/intel64/ifort.exe

After this it then repeats almost exactly this set of outputs for each *.f90 file that is trying to be compiled:

gdk-auto.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.1.216 Build 20200306
Copyright (C) 1985-2020 Intel Corporation. All rights reserved.
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mfpmath=sse’
ifort: command line warning #10006: ignoring unknown option ‘/msse’
ifort: command line warning #10006: ignoring unknown option ‘/msse2’
ifort: command line warning #10006: ignoring unknown option ‘/pthread’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/LC:/msys64/mingw64/lib’
ifort: command line warning #10006: ignoring unknown option ‘/lgtk-4’
ifort: command line warning #10006: ignoring unknown option ‘/lpangowin32-1.0’
ifort: command line warning #10006: ignoring unknown option ‘/lpangocairo-1.0’
ifort: command line warning #10006: ignoring unknown option ‘/lpango-1.0’
ifort: command line warning #10006: ignoring unknown option ‘/lharfbuzz’
ifort: command line warning #10006: ignoring unknown option ‘/lgdk_pixbuf-2.0’
ifort: command line warning #10006: ignoring unknown option ‘/lcairo-gobject’
ifort: command line warning #10006: ignoring unknown option ‘/lcairo’
ifort: command line warning #10006: ignoring unknown option ‘/lvulkan’
ifort: command line warning #10006: ignoring unknown option ‘/lgraphene-1.0’
ifort: command line warning #10006: ignoring unknown option ‘/lgio-2.0’
ifort: command line warning #10006: ignoring unknown option ‘/lgobject-2.0’
ifort: command line warning #10006: ignoring unknown option ‘/lglib-2.0’
ifort: command line warning #10006: ignoring unknown option ‘/lintl’

And then finally, at the end it spits out:

Compiling the examples…
bazaar
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.1.216 Build 20200306
Copyright (C) 1985-2020 Intel Corporation. All rights reserved.
ifort: command line warning #10161: unrecognized source type ‘gtk.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-sup.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘unixonly-auto.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-misc.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-button.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-combobox.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-container.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-entry.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-progress.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-spin-slider.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-tree.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-chooser.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-dialog.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-infobar.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-hl-assistant.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gdk-pixbuf-hl.o’; object file assumed
ifort: command line warning #10161: unrecognized source type ‘gtk-draw-hl.o’; object file assumed
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mfpmath=sse’
ifort: command line warning #10006: ignoring unknown option ‘/msse’
ifort: command line warning #10006: ignoring unknown option ‘/msse2’
ifort: command line warning #10006: ignoring unknown option ‘/pthread’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/mms-bitfields’
ifort: command line warning #10006: ignoring unknown option ‘/LC:/msys64/mingw64/lib’
ifort: command line warning #10006: ignoring unknown option ‘/lgtk-4’
ifort: command line warning #10006: ignoring unknown option ‘/lpangowin32-1.0’
ifort: command line warning #10006: ignoring unknown option ‘/lpangocairo-1.0’
ifort: command line warning #10006: ignoring unknown option ‘/lpango-1.0’
ifort: command line warning #10006: ignoring unknown option ‘/lharfbuzz’
ifort: command line warning #10006: ignoring unknown option ‘/lgdk_pixbuf-2.0’
ifort: command line warning #10006: ignoring unknown option ‘/lcairo-gobject’
ifort: command line warning #10006: ignoring unknown option ‘/lcairo’
ifort: command line warning #10006: ignoring unknown option ‘/lvulkan’
ifort: command line warning #10006: ignoring unknown option ‘/lgraphene-1.0’
ifort: command line warning #10006: ignoring unknown option ‘/lgio-2.0’
ifort: command line warning #10006: ignoring unknown option ‘/lgobject-2.0’
ifort: command line warning #10006: ignoring unknown option ‘/lglib-2.0’
ifort: command line warning #10006: ignoring unknown option ‘/lintl’

ipo: error #11018: Cannot open gtk.o
ipo: error #11018: Cannot open gtk-sup.o
ipo: error #11018: Cannot open gtk-hl.o
ipo: error #11018: Cannot open unixonly-auto.o
ipo: error #11018: Cannot open gtk-hl-misc.o
ipo: error #11018: Cannot open gtk-hl-button.o
ipo: error #11018: Cannot open gtk-hl-combobox.o
ipo: error #11018: Cannot open gtk-hl-container.o
ipo: error #11018: Cannot open gtk-hl-entry.o
ipo: error #11018: Cannot open gtk-hl-progress.o
ipo: error #11018: Cannot open gtk-hl-spin-slider.o
ipo: error #11018: Cannot open gtk-hl-tree.o
ipo: error #11018: Cannot open gtk-hl-chooser.o
ipo: error #11018: Cannot open gtk-hl-dialog.o
ipo: error #11018: Cannot open gtk-hl-infobar.o
ipo: error #11018: Cannot open gtk-hl-assistant.o
ipo: error #11018: Cannot open gdk-pixbuf-hl.o
ipo: error #11018: Cannot open gtk-draw-hl.o
link: unknown option – s
Try ‘link --help’ for more information.

Does this help any or make any sense to you?

Yes, in those warnings you can recognize (except mms-bitfields) the options coming from the pkg-config utility, in one of my last messages. And among these options, those beginning with an l (lowercase L) are essential for linking with the GTK libraries. Hence the final errors: the object files were not generated.

You should search information on linking options in ifort for Windows, for example (but not enough information there):
https://stackoverflow.com/questions/27777477/windows-ifort-linker-library-path
It seems under Windows the ifort options are introduced by a slash / instead of a dash -

Well, I think that I finally got the GTK-Fortran libraries to compile using ifort, thanks to your script and your tip about using / instead of -.

It compiles the .f90 files and generates .mod and .obj files (instead of .o files). I tried correcting all instances of *.o to *.obj within the script, but it still fails to compile any of the examples.

Compiling the examples…
bazaar
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.1.216 Build 20200306
Copyright (C) 1985-2020 Intel Corporation. All rights reserved.
link: unknown option – s
Try ‘link --help’ for more information.

But I don’t see a ‘–s’ anywhere in the script, so I’m not sure what that’s about.

After this success, I pulled the files and the compiled libraries into my actual project in VS and it was able to successfully compile there as well. So now I just have to troubleshoot my actual code to be compatible with the Intel Fortran Compiler, which I could certainly use help with, but I feel like I have already asked for too much help here as is, so feel free to ignore the following troubleshooting.

On the lines that follow the format

use gtk, only: gtk_events_pending, gtk_main, …etc

I get errors of the format

error #6580: Name in only-list does not exist or is not accessible. [GTK_EVENTS_PENDING]

but only on some of them, seemingly randomly.

If I comment out all of the ‘, only:’ portions, then these errors go away.

I then run into errors on the function from JuliaSets:

recursive subroutine pending_events ()
do while(IAND(gtk_events_pending(), run_status) /= FALSE)
boolresult = gtk_main_iteration_do(FALSE) ! False for non-blocking
end do
end subroutine pending_events

Giving:

error #6404: This name does not have a type, and must have an explicit type. [IAND]
error #6404: This name does not have a type, and must have an explicit type. [GTK_EVENTS_PENDING]
error #6363: The intrinsic data types of the arguments must be the same. [IAND]
error #6404: This name does not have a type, and must have an explicit type. [GTK_MAIN_ITERATION_DO]

Next, in my main program code, at the top on the line

use handlers

It gives me the error:

error #7002: Error in opening the compiled module file. Check INCLUDE paths. [HANDLERS]

Which I don’t understand because it’s declared in the same file, just like in the examples included with the GTK-Fortran library.

And then a bunch of errors not liking the ‘c_ptr’ declaration:

error #6457: This derived type name has not been declared. [C_PTR]

So, still a long way to go I imagine, but I’d call this major progress! Thank you so much for you help so far!

1 Like

It’s great if you have successfully build the library!

But it seems you have problems with linking the examples with the gtk-fortran modules. So you will have an avalanche of error messages.

My advice is: don’t try to fix all problems simultaneously. Just try to build the simplest example: examples/gtkzero_gapp.f90. It just opens an empty GTK window: in its code you will find a use gtk, only: and a use g, only: (g is for GLib). So you just have to successfully link that example with the gtk and g modules of gtk-fortran, and of course the GTK and GLib libraries of the GTK collection.

When you will have succeeded with that example, everything else will follow…

Hey vmagnin,

So, I went over to the Intel Community forums to try and get help tracking down issues that were specific to VS/ifort. I was able to create a static library project that successfully compiles the GTK-Fortran library in VS. But when trying to compile a project from the gtkzero_gapp.f90 example, I get errors saying “unresolved external symbol”.

Severity Code Description Project File Line Suppression State
Error error LNK2019: unresolved external symbol g_signal_connect_data referenced in function GTK_mp_FUNCTION_G_SIGNAL_CONNECT GTK-Fortran-iFort.lib(gtk.obj)
Error error LNK2019: unresolved external symbol gtk_widget_show referenced in function activate gtkzero_gapp.obj
Error error LNK2019: unresolved external symbol gtk_window_set_title referenced in function activate gtkzero_gapp.obj
Error error LNK2019: unresolved external symbol g_object_unref referenced in function MAIN__ gtkzero_gapp.obj
Error error LNK2019: unresolved external symbol gtk_application_new referenced in function MAIN__ gtkzero_gapp.obj
Error error LNK2019: unresolved external symbol gtk_application_window_new referenced in function activate gtkzero_gapp.obj
Error error LNK2019: unresolved external symbol g_application_run referenced in function MAIN__ gtkzero_gapp.obj
Error error LNK2019: unresolved external symbol gtk_window_set_default_size referenced in function activate gtkzero_gapp.obj
Error fatal error LNK1120: 8 unresolved externals x64\Release\Test3.exe

The people over there responded to these errors saying

“It looks to me as if there is a separate GTK library you need. What you have is only the Fortran interface to it. None of the missing symbols are defined in the sources you have (other than as interfaces). When you find it, you can simply add the .lib as a source file in your executable project.”

I remember including the libgtk-<3/4>-fortran.dll<.a> file(s) when I was testing the GTK-Fortran library in Code::Blocks IDE, but when I include those in the VS project, I still get the same errors listed above. Any ideas on what I need to be including for the compiler to be able to find these functions?

Thanks,
Bryan

The goal is near, but yes, there is still a linking problem.

All I can say is that under Linux, having the GTK libraries installed is not sufficient if you want to build your own program: you also need the development files. In the case of my Ubuntu system it is the libgtk4-dev package (and its dependencies): “This package contains the header and development files which are needed for building GTK applications.”

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