-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to build a simple gtk-fortran example: how to link with gtk-4-fortran? #487
Comments
External module files have to declared explicitly, see here. In this case it would require an additional entry in the build section: [build]
link = "gtk-4-fortran"
external-modules = ["gtk", "g"] |
My fpm does not like that new line :-( $ fpm build --flag "$(pkg-config --cflags --libs gtk-4-fortran)"
Key external-modules is not allowed in [build]
ERROR STOP 1
Error termination. Backtrace:
#0 0x7f641f428820 in ??? Perhaps not yet in fpm 0.2.0 ? |
You're right, it was added with #438 but hasn't been released yet. |
This might be resolved with the freshly released fpm version 0.3.0 |
Thanks @awvwgk for the information, |
@awvwgk $ fpm build --flag '$(pkg-config --cflags --libs gtk-4-fortran)'
+ mkdir -p build/dependencies
+ mkdir -p build/gfortran_4E42016360FFAE8D/gtkzero_fpm
+ gfortran -c test/check.f90 $(pkg-config --cflags --libs gtk-4-fortran) -J build/gfortran_4E42016360FFAE8D/gtkzero_fpm -I build/gfortran_4E42016360FFAE8D/gtkzero_fpm -o build/gfortran_4E42016360FFAE8D/gtkzero_fpm/test_check.f90.o
+ gfortran -c ././src/handlers.f90 $(pkg-config --cflags --libs gtk-4-fortran) -J build/gfortran_4E42016360FFAE8D/gtkzero_fpm -I build/gfortran_4E42016360FFAE8D/gtkzero_fpm -o build/gfortran_4E42016360FFAE8D/gtkzero_fpm/src_handlers.f90.o
+ ar -rs build/gfortran_4E42016360FFAE8D/gtkzero_fpm/libgtkzero_fpm.a build/gfortran_4E42016360FFAE8D/gtkzero_fpm/src_handlers.f90.o
ar: création de build/gfortran_4E42016360FFAE8D/gtkzero_fpm/libgtkzero_fpm.a
+ gfortran -c app/main.f90 $(pkg-config --cflags --libs gtk-4-fortran) -J build/gfortran_4E42016360FFAE8D/gtkzero_fpm -I build/gfortran_4E42016360FFAE8D/gtkzero_fpm -o build/gfortran_4E42016360FFAE8D/gtkzero_fpm/app_main.f90.o
+ mkdir -p build/gfortran_4E42016360FFAE8D/app/
+ gfortran $(pkg-config --cflags --libs gtk-4-fortran) -J build/gfortran_4E42016360FFAE8D/gtkzero_fpm -I build/gfortran_4E42016360FFAE8D/gtkzero_fpm build/gfortran_4E42016360FFAE8D/gtkzero_fpm/app_main.f90.o build/gfortran_4E42016360FFAE8D/gtkzero_fpm/libgtkzero_fpm.a -lgtk-4-fortran -o build/gfortran_4E42016360FFAE8D/app/gtkzero_fpm
/usr/bin/ld: build/gfortran_4E42016360FFAE8D/gtkzero_fpm/app_main.f90.o: undefined reference to symbol 'gtk_application_new'
/usr/bin/ld : /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libgtk-4.so : erreur lors de l'ajout de symboles : DSO missing from command line
collect2: error: ld returned 1 exit status
<ERROR> Compilation failed for object "gtkzero_fpm"
STOP 1 Note that if I type the following command, it compiles and runs: $ gfortran src/handlers.f90 app/main.f90 $(pkg-config --cflags --libs gtk-4-fortran) |
The problem is that you are adding the libs with the You probably have to add the output of |
Thanks Sebastian @awvwgk I have separated the
In the
The problem is that on the compilation command lines, only the first library is prefixed with
In that case, the build is OK with:
But if I run: $ fpm run
+ mkdir -p build/gfortran_2A42023B310FA28D/gtkzero_fpm
+ gfortran -c test/check.f90 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran_2A42023B310FA28D/gtkzero_fpm -I build/gfortran_2A42023B310FA28D/gtkzero_fpm -o build/gfortran_2A42023B310FA28D/gtkzero_fpm/test_check.f90.o
+ gfortran -c ./src/handlers.f90 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran_2A42023B310FA28D/gtkzero_fpm -I build/gfortran_2A42023B310FA28D/gtkzero_fpm -o build/gfortran_2A42023B310FA28D/gtkzero_fpm/src_handlers.f90.o
./src/handlers.f90:7:7:
7 | use gtk, only: gtk_window_set_default_size, gtk_window_set_title, &
| 1
Fatal Error: Cannot open module file ‘gtk.mod’ for reading at (1): Aucun fichier ou dossier de ce type
compilation terminated.
<ERROR> Compilation failed for object "src_handlers.f90.o"
STOP 1 Finally it runs successfully if I use the $ fpm run --flag '$(pkg-config --cflags gtk-4-fortran) -Xlinker -R/usr/local/lib' |
build.link = [
"gtk-4",
"pangocairo-1.0",
"pango-1.0",
"harfbuzz",
"gdk_pixbuf-2.0",
"cairo-gobject",
"cairo",
"vulkan",
"graphene-1.0",
"gio-2.0",
"gobject-2.0",
"glib-2.0",
"gtk-4-fortran",
] It's quite a lot of libraries to specify explicitly, unfortunately. |
OK @awvwgk , I should have thought that it must be a list like in my So, now everything is OK with those commands: $ fpm build --flag '$(pkg-config --cflags gtk-4-fortran) -Xlinker -R/usr/local/lib' and $ fpm run --flag '$(pkg-config --cflags gtk-4-fortran) -Xlinker -R/usr/local/lib' But I don't understand why I am obliged to use |
Note also that all the libraries are not needed for all programs, that's just for the general case.
|
fpm is stateless, if you use Better pkg-config support would resolve this issue of having to use [dependencies]
gtk-4-fortran.pkg-config = "gtk-4-fortran" could be an option. |
Thanks for all! |
I have created a small repository with the example I am trying to build as an fpm project:
https://github.com/vmagnin/gtkzero_fpm
It is the
gtkzero_gapp.f90
available in the gtk-fortran gtk4 branch: it just opens an empty GTK 4 window. As the original file contains the main program and ahandlers
module, I have put that module insrc/handlers.f90
. The main program has been renamed:app/main.f90
.My fpm version is 0.2.0 alpha. I have tried adding
link = "gtk-4-fortran"
in the[build]
section of thefpm.toml
file, but it does not change anything.Same error if I replace the apostrophes by double quotes.
This is the output of the pkg-config command on my machine:
The gtk-fortran modules are here:
The text was updated successfully, but these errors were encountered: