As promised (see thread "[Pkg-pascal-devel] New project gtk4pas" with Mazen,
and prompted by Abou in
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=967284 ), I made a
modification to Castle Game Engine to enable using GTK 3 units from
fp-units-gtk3 ( https://gitlab.com/gtk4pas/gtk3bindings ).
Below I report my experience, and 1 thing you possibly want to fix
(gtk_widget_set_events incompatibility) and 1 issue we really need fixing
(linking).
First, info how do I test:
1. This was all tested on latest Debian testing, a fresh system as of today,
with FPC and fp-units-gtk3 from packages (`apt install fpc fp-units-gtk3
libgtk-3-dev`).
2. I use latest Castle Game Engine from GitHub master,
https://github.com/castle-engine/castle-engine/ . I clone the engine repo,
build our "build tool" ("cd castle-engine/tools/build-tool &&
./castle-engine_compile.sh"), then build example ("cd examples/terrain &&
castle-engine compile-run").
3. With our default GTK3 bindings, which are fork (copy+adjust by script) from
Lazarus (see
https://github.com/castle-engine/castle-engine/tree/master/src/window/gtk/gtk3
) all builds and executes well.
4. To switch to use fp-units-gtk3: just define CASTLE_GTK3_UNITS_GTK4PAS symbol
and we'll use GTK3 units like "GObject2, Glib2, Gdk3, Gtk3". This was done in
https://github.com/castle-engine/castle-engine/commit/e88fdb07fed6bfc4290280070e227e35211f3db6
. You can define CASTLE_GTK3_UNITS_GTK4PAS really anywhere, as long as it
effects CastleWindow unit compilation, in particular inside
`src/window/gtk/castlewindow_gtk.inc` file is OK. A minimal patch to put
`{$define CASTLE_GTK3_UNITS_GTK4PAS}` at the top of
`src/window/gtk/castlewindow_gtk.inc` will do the trick, assuming you will want
future Debian's CGE version depend on fp-units-gtk3.
Observations and possible things to fix in fp-units-gtk3 :
5. I needed to change the gtk_widget_set_events call. See
https://github.com/castle-engine/castle-engine/commit/e88fdb07fed6bfc4290280070e227e35211f3db6
. For some reason, in latest version I took from Lazarus GTK3 bindings, this
expects a Pascal set, while in fp-units-gtk3 this expects a simple integer. Of
course binary it doesn't matter, it's the same thing for C. I don't know why
there's a difference in how Pascal bindings define it (was the same version of
git2pas used to generate them? which version used newer git2pas version?) and
what is "more reliable in the future" -- I can adjust as needed to
https://gitlab.com/gtk4pas/gtk3bindings changes, no problem :)
6. The critical problem is that project doesn't link with fp-units-gtk3 . I'm
attaching full output, the core are linking issues:
"""
/usr/bin/x86_64-linux-gnu-ld.bfd:
/usr/lib/x86_64-linux-gnu/fpc/3.2.2/units/x86_64-linux/gtk3/glib2.o: in
function `GLIB2$_$TGMAINCONTEXT_$__$$_PUSHER_NEW$$PGMAINCONTEXTPUSHER':
glib2.pas:(.text.n_glib2$_$tgmaincontext_$__$$_pusher_new$$pgmaincontextpusher+0x15):
undefined reference to `g_main_context_pusher_new'
/usr/bin/x86_64-linux-gnu-ld.bfd:
/usr/lib/x86_64-linux-gnu/fpc/3.2.2/units/x86_64-linux/gtk3/glib2.o: in
function `GLIB2$_$TGMAINCONTEXT_$__$$_PUSHER_FREE$PGMAINCONTEXTPUSHER':
glib2.pas:(.text.n_glib2$_$tgmaincontext_$__$$_pusher_free$pgmaincontextpusher+0x19):
undefined reference to `g_main_context_pusher_free'
/usr/bin/x86_64-linux-gnu-ld.bfd:
/usr/lib/x86_64-linux-gnu/fpc/3.2.2/units/x86_64-linux/gtk3/glib2.o: in
function `GLIB2$_$TGTHREAD_$__$$_INIT$POINTER':
glib2.pas:(.text.n_glib2$_$tgthread_$__$$_init$pointer+0x19): undefined
reference to `g_thread_init'
/usr/bin/x86_64-linux-gnu-ld.bfd:
/usr/lib/x86_64-linux-gnu/fpc/3.2.2/units/x86_64-linux/gtk3/glib2.o: in
function `GLIB2$_$TGTHREAD_$__$$_INIT_WITH_ERRORCHECK_MUTEXES$POINTER':
glib2.pas:(.text.n_glib2$_$tgthread_$__$$_init_with_errorcheck_mutexes$pointer+0x19):
undefined reference to `g_thread_init_with_errorcheck_mutexes'
"""
>From a quick glance, I'm not sure what is culprit -- g_main_context_pusher_new
>should be in my libraries (it's in glib >= 2.64 , according to
>https://docs.gtk.org/glib/method.MainContext.pusher_new.html , and latest
>Debian testing has 2.87.2-3 , according to "dpkg -l libglib2.0*").
For now, this is what I know. We need to solve AD 6 above to make it really
work :) If noone will have any idea, I'll of course just submit a Debian bug
about it.
Regards,
MichalisCompiling project "terrain" for OS / CPU "linux / x86_64" in mode "release".
FPC executing...
Compiling Release Version
Free Pascal Compiler version 3.2.2+dfsg-49 [2026/02/27] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling terrain_standalone.dpr
User defined: Thread support enabled.
Compiling
/home/michalis/sources/castle-engine/castle-engine/src/window/castlewindow.pas
Compiling
/home/michalis/sources/castle-engine/castle-engine/src/window/castleinternalwindowmodes.pas
/home/michalis/sources/castle-engine/castle-engine/src/window/gtk/gtk_3.inc(107,20)
Warning: Symbol "gdk_display_get_device_manager" is deprecated: "Use
gdk_display_get_default_seat() and #GdkSeat operations."
/home/michalis/sources/castle-engine/castle-engine/src/window/gtk/gtk_3.inc(108,13)
Warning: Symbol "gdk_device_manager_get_client_pointer" is deprecated: "Use
gdk_seat_get_pointer() instead."
/home/michalis/sources/castle-engine/castle-engine/src/window/gtk/castlewindow_gtk.inc(975,24)
Warning: Symbol "gdk_screen_width_mm" is deprecated: "Use per-monitor
information"
/home/michalis/sources/castle-engine/castle-engine/src/window/gtk/castlewindow_gtk.inc(982,19)
Warning: Symbol "gdk_screen_width" is deprecated: "Use per-monitor information"
/home/michalis/sources/castle-engine/castle-engine/src/window/gtk/castlewindow_gtk.inc(2031,14)
Warning: Symbol "gdk_screen_get_primary_monitor" is deprecated: "Use
gdk_display_get_primary_monitor() instead"
/home/michalis/sources/castle-engine/castle-engine/src/window/gtk/castlewindow_gtk.inc(2032,3)
Warning: Symbol "gdk_screen_get_monitor_geometry" is deprecated: "Use
gdk_monitor_get_geometry() instead"
/home/michalis/sources/castle-engine/castle-engine/src/window/gtk/castlewindow_gtk.inc(2046,14)
Warning: Symbol "gdk_screen_get_primary_monitor" is deprecated: "Use
gdk_display_get_primary_monitor() instead"
/home/michalis/sources/castle-engine/castle-engine/src/window/gtk/castlewindow_gtk.inc(2047,3)
Warning: Symbol "gdk_screen_get_monitor_geometry" is deprecated: "Use
gdk_monitor_get_geometry() instead"
Compiling castleautogenerated.pas
Compiling ./code/gameinitialize.pas
Linking terrain_standalone
Warning: "crtbegin.o" not found, this will probably cause a linking failure
Warning: "crtend.o" not found, this will probably cause a linking failure
/usr/bin/x86_64-linux-gnu-ld.bfd:
/usr/lib/x86_64-linux-gnu/fpc/3.2.2/units/x86_64-linux/gtk3/glib2.o: in
function `GLIB2$_$TGMAINCONTEXT_$__$$_PUSHER_NEW$$PGMAINCONTEXTPUSHER':
glib2.pas:(.text.n_glib2$_$tgmaincontext_$__$$_pusher_new$$pgmaincontextpusher+0x15):
undefined reference to `g_main_context_pusher_new'
/usr/bin/x86_64-linux-gnu-ld.bfd:
/usr/lib/x86_64-linux-gnu/fpc/3.2.2/units/x86_64-linux/gtk3/glib2.o: in
function `GLIB2$_$TGMAINCONTEXT_$__$$_PUSHER_FREE$PGMAINCONTEXTPUSHER':
glib2.pas:(.text.n_glib2$_$tgmaincontext_$__$$_pusher_free$pgmaincontextpusher+0x19):
undefined reference to `g_main_context_pusher_free'
/usr/bin/x86_64-linux-gnu-ld.bfd:
/usr/lib/x86_64-linux-gnu/fpc/3.2.2/units/x86_64-linux/gtk3/glib2.o: in
function `GLIB2$_$TGTHREAD_$__$$_INIT$POINTER':
glib2.pas:(.text.n_glib2$_$tgthread_$__$$_init$pointer+0x19): undefined
reference to `g_thread_init'
/usr/bin/x86_64-linux-gnu-ld.bfd:
/usr/lib/x86_64-linux-gnu/fpc/3.2.2/units/x86_64-linux/gtk3/glib2.o: in
function `GLIB2$_$TGTHREAD_$__$$_INIT_WITH_ERRORCHECK_MUTEXES$POINTER':
glib2.pas:(.text.n_glib2$_$tgthread_$__$$_init_with_errorcheck_mutexes$pointer+0x19):
undefined reference to `g_thread_init_with_errorcheck_mutexes'
Error: Error while linking
Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode
Exception "Exception":
Failed to compile