Closed ifemi closed 3 years ago
The main issue seems to be: `./gtk-src/gtk.f90:53:8:
53 | use g, only: g_signal_connect_data | 1 Fatal Error: Cannot open module file ‘g.mod’ for reading at (1): No such file or directory`
Welcome @ifemi ,
you must compile the files in a precise order: if a file uses a module, the module must be placed before in the compilation command line:
./gtk-src/glib-auto.f90 ./gtk-src/gtk.f90 ./gtk-examples/gtkhello.f90
because gtkhello.f90
uses the gtk
module which uses the g
module (g stands for glib).
And for more complicated examples you may need to identify and compile more modules. That's why it's better to use CMake and install the gtk-fortran library in your system (see https://github.com/vmagnin/gtk-fortran/wiki#linux).
Then compiling a program will be very easy:
$ gfortran ./gtk-examples/gtkhello.f90 $(pkg-config --cflags --libs gtk-3-fortran)
As you are the first user to report using WSL, let me know your progress. Are you using WSL1 or WSL2?
Very many thanks @vmagnin everything is quite ok now
I did use CMake to install gtk-fortran.
My environment is WSL2, Ubuntu-20.04 and Visual Studio Code as IDE and of course gfortran, gtk-fortran and glade for the UI
NOTE:
In VS Code the command used in the task.json is:
gfortran ${file} pkg-config --cflags --libs gtk-3-fortran
-o ${fileDirname}/${fileBasenameNoExtension}.out
However that gives a permision error and so I had to sudo is and provide the password when requested.
Without sudo:
`/gtk-examples/gtkhello.f90:72:19:
72 | end module handlers | 1 Fatal Error: Cannot open module file ‘handlers.mod0’ for writing at (1): Permission denied compilation terminated.`
@vmagnin is there a way of getting past the permission problem?
@ifemi , thanks for sharing information about WSL2 and VS Code, that could be useful for other users! Does the compilation command works in command line? It seems VS Code is running gfortran from a directory where it has no permission.
Maybe you could try using the gfortran's -J
option:
-Jdir This option specifies where to put .mod files for compiled modules. It is also added to the list of directories to searched by an "USE" statement. The default is the current directory.
Many thanks @vmagnin it worked on the command line.
The -Jdir worked perfectly. Please note for VS Code I used:
"gfortran -g -J${fileDirname} ${file} pkg-config --cflags --libs gtk-3-fortran
-o ${fileDirname}/${fileBasenameNoExtension}.out"
or
"gfortran -g -J${fileDirname} ${file} pkg-config --cflags --libs gtk-3-fortran
-o ${fileDirname}/${fileBasenameNoExtension}"
Describe the bug I ran the following:
gfortran
pkg-config --cflags --libs gtk+-3.0./gtk-examples/gtkhello.f90 ./gtk-src/gtk.f90
Expected behavior Expected to compile and run a gui
To Reproduce
Your system:
Additional context Error:
`./gtk-examples/gtkhello.f90:35:6:
35 | use gtk, only: gtk_main_quit, FALSE | 1 Fatal Error: Cannot open module file ‘gtk.mod’ for reading at (1): No such file or directory compilation terminated. ./gtk-src/gtk.f90:53:8:
53 | use g, only: g_signal_connect_data | 1 Fatal Error: Cannot open module file ‘g.mod’ for reading at (1): No such file or directory compilation terminated.`