vmagnin/gtk-fortran

Compilation error on Windows

maurosgroi opened this issue · 7 comments

Dear developer,
my name is Mauro Sgroi and I'm trying to install gtk.fortran on Cygwin64. I would prefer to use Cygwin with respect to Msys2 since I exensively use Cygwin for other applications.
I succeeded to compile Plplot and configured gtk.fortran with:

PKG_CONFIG_PATH=/home/sgroi/apps/plplot/5.15.0/lib/pkgconfig cmake -DCMAKE_INSTALL_PREFIX=/home/sgroi/apps/gtk-fortran ../

During compilation I get the error:

[ 24%] Built target gtk-fortran_shared
[ 25%] Linking Fortran executable gtk-3-fortran.exe
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: CMakeFiles/gtk-3-fortran.dir/gtk-fortran.f90.o:gtk-fortran.f90:(.text+0x169): undefined reference to g_get_os_info' CMakeFiles/gtk-3-fortran.dir/gtk-fortran.f90.o:gtk-fortran.f90:(.text+0x169): relocation truncated to fit: R_X86_64_PC32 against undefined symbol g_get_os_info'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/gtk-3-fortran.dir/build.make:105: src/gtk-3-fortran.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:415: src/CMakeFiles/gtk-3-fortran.dir/all] Error 2
make: *** [Makefile:183: all] Error 2

Is there a way to fix this problem?
Thanks a lot and best regards,
Mauro Sgroi.

Welcome Mauro @maurosgroi !
I have no experience about cygwin (or a very long time ago).
But this is a linking error and the g_get_os_info() function is a part of the GLib:
https://developer.gnome.org/glib/unstable/glib-Miscellaneous-Utility-Functions.html#g-get-os-info
and that documentation says it is present since GLib 2.64.

Can you look at your GLib version ?
If it is <2.64 there is two solutions:

But looking at https://cygwin.com/cgi-bin2/package-grep.cgi?grep=glib&arch=x86_64 it seems the latest available GLib is 2.54. Which corresponds to the gtk-fortran 17.10 release, quite old...
It inspires me two other solutions that may work:

  • You may try to edit the src/glib-auto.f90 file and delete all the Fortran interfaces that cause a build error.
  • As a quicker solution, you may try to replace the actual src/glib-auto.f90 file by its gtk-fortran 17.10 version.

Dear vmagnin,
the substitution of glib.auto.f90 with an onlde version causes other errors..
How can I understand which are the fortran interfaces that give errors?
Best regards,
Mauro.

The message undefined reference to g_get_os_info means the linker does not find the function g_get_os_info() into your GLib version. So you can try to delete its Fortran interface in glib-auto.f90 and rebuild.
The problem is that you will have to make that for each missing function. If you must do it 10 times it's OK, but if it happens 100 times... :-(

Did you try with the v17.10 glib-auto.f90 file ?

You can also have a look at: https://linux.die.net/man/1/ld
to the --unresolved-symbols option of the ld linker.

I removed g_get_os_info from glib-auto.f90 and the call:

call c_f_string_copy(g_get_os_info("PRETTY_NAME"//c_null_char), os_string) in the gtk-fortran.f90 file.

Now the package compiles.

Will it be functional? Or the modifications risk to compromise it?

Best regards,
Mauro.

Fine, happily there is only one missing function!
There is no problem, the gtk-fortran.f90 utility is really not necessary for using gtk-fortran. It is just a command to show some information, like the GTK version installed on the machine. It can be useful for example if you don't remember the pkg-config command:

$ ./gtk-3-fortran
gtk-3-fortran (Ubuntu 20.10, GTK 3.24.23)
Licensed under GNU GPL 3 with the additional permissions described in the GCC Runtime Library Exception version 3.1
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Usage example:
gfortran my_app.f90 $(pkg-config --cflags --libs gtk-3-fortran)

Documentation: https://github.com/vmagnin/gtk-fortran/wiki
Bug reports:   https://github.com/vmagnin/gtk-fortran/issues
$

Great!
Thanks a lot and best regards,
Mauro Sgroi.