Building Gtkada on Windows 11 gives errors/warnings on misc.c

Platform Windows 11, with MSYS2 installed. I want to compile Gtkada and I know that I need Alire to do so.
So, I do “alr -b get Gtkada^25”. Alire gets Gtkada (25.0.0) and builds it. However at the end it produces 2 warnings on misc.c but a gtkada.a library is produced. And I could actually create a working program using Gtkada.

  • What is needed (environment vars, search paths, …) to get an error/warning free compilation of misc.c

  • The warnings are:
    [C] misc.c
    D:\ada\gtkada\gtkada_25.0.1_d3787772\src\misc.c: In function ‘ada_gdk_event_get_keyval’:
    D:\ada\gtkada\gtkada_25.0.1_d3787772\src\misc.c:765:39: warning: result of ‘2 << 31’ requires 34 bits to represent, but ‘int’ only has 32 bits [-Wshift-overflow=]
    765 | #define ada_gdk_invalid_gint_value ((2<<31) - 1)
    | ^~
    D:\ada\gtkada\gtkada_25.0.1_d3787772\src\misc.c:814:12: note: in expansion of macro ‘ada_gdk_invalid_gint_value’
    814 | return ada_gdk_invalid_gint_value;
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~
    D:\ada\gtkada\gtkada_25.0.1_d3787772\src\misc.c: In function ‘ada_gtk_application_startup’:
    D:\ada\gtkada\gtkada_25.0.1_d3787772\src\misc.c:2001:5: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
    2001 | g_application_get_application_id (G_APPLICATION (application));
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • Are they troublesome ?

NOTE : when doing “alr -b get gtkada” (the default) Alire gets version 24.0.0. and it produces errors on misc.c and does not produce a gtkada.a library. However after some not reproducible fiddling with envvars and search paths I got 24.0.0 working without any errors/warnings. Alas, for the life of me I have no clue what I did

How do you know that? :grinning:

What you actually need is Ada and C compilers,. configure/make stuff, GTK, GtkAda sources.

In order to compile GtkAda under MSYS, download the archive from the repository. Then you deflate the archive and unpack it in a directory, say d:\gtkada. Then:

  1. Start MSYS64 console
  2. cd /d/gtkada
  3. If you have Ada compiler installed outside MSYS, add its bin directory to the PATH (e.g. export PATH=/c/GNAT/2010/bin:$PATH)
  4. Install GTK in MSYS
  5. ../configure --with-GL=no
  6. make
  7. Install the result in the directory you want (make install) see step 5, option --prefix of configure allows to specify the install directory.

You are done.

P.S. I guess you do not need the latest GtkAda version. It is pretty much stable.

P.P.S. Youi can always take precompiled GTK+GtkAda from a GPS (GNAT studio) distribution without MSYS stuff. However it would lack some things like GtkSourceView etc.

Msys2 also provides a pre built version of gtkada via pacman

Thanks for your reply, Dmitry,
(I hope that the quotes format Ok, in the reply box they are just plain text) (I am new to this forum as you probably guessed already)

I refrase: I more or less digested it from Google searches as the least troublesome way to do it. I was wrong …

I have 5 options: “MSYS2 MSYS”, “MSYS2 MINGW64”, “MSYS UCRT64”, “MSYS2 CLAN64”, “MSYS2 CLANGARM64”.
I guess it is the MINGW64 console. The ARM version is obvious not OK

Could you elaborate a bit on that? Do I need to do something like “pacman get GTK-3” or so?

The latest GTK+Gtkada installable I have is a 2021 version. But if it is stable I keep on using it and spare me the hassle of Alire. The use of that installable eliminates the need for MSYS.

OK. Thanks. I look into that. I was hoping to create a Gtkada build without the need for MSYS modules. But that ship has sailed I guess if I want to use a later GTKADA version than the one from the 2021 distribution.

Be careful using the old community versions. I don’t know about gtkada specifically but their gnat installation had a less permissive license (gpl without linking exceptions). Though as long as you are ok with the license applying to your own software it’s fine either way (and gtkada may be different… Never checked its license)

  1. MSYS2 MinGW 64-bit starts the console.
  2. ARM? MSYS is X86_64/i686
  3. Does MSYS2 minimal installation includes GTK? I do not remember. You may need to run pacman -S mingw64/mingw-w64-x86_64-gtk3
  4. GtkAda is Ada2005. You can use any GNAT compiler with it.

Thanks Dmitry and Jere for your quick responses. Very helpful!

If only life were that simple. Alas …
The compiler can be found on PATH
Used pacman to install GTK-3 and added
Added the path where GTK-3 was installed (/d/msys64/mingw64/share) to PATH
Then, running ./configure gives the following error (Note: ./configure doesn’t recognize the --with-GL option):

checking for GTK… no
configure: error: in `/d/ada/gtkada-25.0.0’:
configure: error: The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.

Alternatively, you may set the environment variables GTK_CFLAGS
and GTK_LIBS to avoid the need to call pkg-config.
<<<<<

There is no pkg-config in MSYS
I have no idea what values these envvar should have.
I could try to build pkg-config from source but then there is still the question of the missing pkg-config script as is stated in the output of ./configure. And where should pkg-config be installed ?
(I am sorry that this thread now seems to develop into a non-Ada and non-GNAT topic.)

You must install gtk3:

# pacman -S mingw-w64-x86_64-gtk3

You must not play with paths. After installation it will be:

# pacman -Ss mingw-w64-x86_64-gtk3
mingw64/mingw-w64-x86_64-gtk3 3.24.33-2 [installed]
    GObject-based multi-platform GUI toolkit (v3) (mingw-w64)

pkg-config comes with gtk3:

# pacman -Ss mingw-w64-x86_64-pkg-config
mingw64/mingw-w64-x86_64-pkg-config 0.29.2-3 [installed]
    A system for managing library compile/link flags (mingw-w64)
mingw64/mingw-w64-x86_64-pkgconf 1.8.0-2 (mingw-w64-x86_64-toolchain)
    pkg-config compatible utility which does not depend on glib

That’s no problem. They seem have removed GL support. Do not use the option.

and you should not care…

I have (had) gtk-3 installed. I did;
$ pacman -S mingw-w64-x86_64-gtk3
warning: mingw-w64-x86_64-gtk3-3.24.49-1 is up to date – reinstalling
resolving dependencies…
looking for conflicting packages…

and then

$ pacman -Ss mingw-w64-x86_64-gtk3
mingw64/mingw-w64-x86_64-gtk3 3.24.49-1 [installed]
GObject-based multi-platform GUI toolkit (v3) (mingw-w64)

$ pacman -Ss mingw-w64-x86_64-pkg-config
mingw64/mingw-w64-x86_64-pkg-config 0.29.2-6
A system for managing library compile/link flags (mingw-w64)
mingw64/mingw-w64-x86_64-pkgconf 1~2.3.0-1 (mingw-w64-x86_64-toolchain)
pkg-config compatible utility which does not depend on glib

./configure gives the same result:
checking for gprbuild… /d/ada/GNAT/bin/gprbuild
checking for gprinstall… /d/ada/GNAT/bin/gprinstall
checking that your gnat compiler works with a simple example… yes
checking whether NLS is requested… yes
checking for gettext in libc… no
checking for bindtextdomain in -lintl… no
checking for GTK… no
configure: error: in `/d/ada/gtkada-25.0.0’:
configure: error: The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.

There is a gtk+3.0.pc file in /mingw64/lib/pkgconfig and /mingw64/lib is on PATH

pkg-config is not installed.

Ouch. I stand corrected and feel foolish

After installing pgk-config the ./configure finished, with warnings that it couldn’t build a Gtk test app.
Then I installed make (!) I ran make. All Ada modules compiles. Unfortunately, misc_generated. and misc.c failed to compile:
[C] misc_generated.c
[C] misc.c
D:\ada\gtkada-25.0.0\src\misc_generated.c:27:10: fatal error: gtk/gtk.h: No such file or directory
27 | #include <gtk/gtk.h>
| ^~~~~~~~~~~
compilation terminated.
D:\ada\gtkada-25.0.0\src\misc.c:35:10: fatal error: glib.h: No such file or directory
35 | #include <glib.h>
| ^~~~~~~~
compilation terminated.

(Of course, “make install” now also fails as there is no libgtkada.a to install)

The missing files are available in /mingw64/include/glib-2.0 and
/mingw64/include/gtk. Apparently they can’t be found by the compiler.
As Dmitry warned against fiddling with search paths and envvars, I am stuck again

Don’t be. I thought that pkg-config will be installed automatically. Before it was so that gtk (glib?) and pkg-config were dependent on each other. Due to this circular dependency its was basically impossible to bootstrap gtk. Now, it seems that they fixed that a bit.

Since compiling/building by make failed I tried to individually compile misc_generated.c and misc.c. After some tries to get the right command I used

$ gcc pkg-config --cflags --libs gtk+-3.0 -c misc_generated.c
this compiled without errors

then
$ gcc pkg-config --cflags --libs gtk+-3.0 glib-2.0 pango gdk-3.0 -c misc.c
this produced a lot of errors and 2 warnings

so this avenue of approach also failed miserably

(Curious thing: although make (and gprbuild) say they are building a static library the results are placed in \src\obj\gtkada\relocatable and \src\lib\gtkada\relocatable )

Note in the above commands the “ticks” enclosing the pkg-config part are missing

Nope, it compiles perfectly well.

Was ./configure successful?

Here is the output (I have an external compiler installed under C:\GNAT\2010):

# export PATH=/c/GNAT/2021/bin:$PATH

# ./configure
configure: loading site script /etc/config.site
checking build system type... x86_64-w64-mingw32
checking host system type... x86_64-w64-mingw32
checking target system type... x86_64-w64-mingw32
checking for pkg-config... /mingw64/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gprbuild... /c/GNAT/2021/bin/gprbuild
checking for gprinstall... /c/GNAT/2021/bin/gprinstall
checking that your gnat compiler works with a simple example... yes
checking whether NLS is requested... yes
checking for gettext in libc... no
checking for bindtextdomain in -lintl... yes
checking for gettext in libintl... checking for gettext in -lintl... yes
yes
checking for GTK... yes
checking for pkg-config... (cached) /mingw64/bin/pkg-config
checking pkg-config is at least version 0.16... yes
checking for GTK+ - version >= 3.24.24... yes (version 3.24.33)
checking for GMODULE... yes
checking for FONTCONFIG... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating gtkada_shared.gpr
config.status: creating po/Makefile
config.status: creating docs/gtkada_rm/html/static/index.html
configure: --------- Summary for Gtkada 18.0w -----------------
configure:   Shared libraries:       yes (default: static)
configure: --------------------------------------------

There is nothing curious about it. Use

./configure --help

to see the list of options. You can build static and/or relocatable versions of the library.

The ultimate destination is controlled by the option --prefix. After doing make, you need make install to set the built GtkAda in place.

It was and it wasn’t
Below my results of ./configure

rob@rob-laptop-win10 MINGW64 /d/ada/gtkada-25.0.0
$ ./configure
configure: loading site script /etc/config.site
checking build system type... x86_64-w64-mingw32
checking host system type... x86_64-w64-mingw32
checking target system type... x86_64-w64-mingw32
checking for pkg-config... /mingw64/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gprbuild... /d/ada/GNAT/bin/gprbuild
checking for gprinstall... /d/ada/GNAT/bin/gprinstall
checking that your gnat compiler works with a simple example... yes
checking whether NLS is requested... yes
checking for gettext in libc... rm: cannot remove 'conftest.exe': Device or resource busy
no
checking for bindtextdomain in -lintl... no
checking for GTK... yes
checking for pkg-config... (cached) /mingw64/bin/pkg-config
checking pkg-config is at least version 0.16... yes
checking for GTK+ - version >= 3.24.24... no
*** Could not run GTK+ test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occurred. This usually means GTK+ is incorrectly installed.
checking for GMODULE... yes
checking for FONTCONFIG... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating gtkada_shared.gpr
config.status: creating po/Makefile
config.status: creating docs/gtkada_rm/html/static/index.html
configure: --------- Summary for Gtkada 18.0w -----------------
configure:   Shared libraries:       yes (default: static)
configure: --------------------------------------------

The my output differences are

  1. checking for gettext in libc… rm: cannot remove ‘conftest.exe’: Device or resource busy
    no.
    But then it goes on with the next test, so the result of the test was Yes (configure lines 3573 .. 3601)

  2. checking for GTK+ - version >= 3.24.24… no
    *** Could not run GTK+ test program, checking why…
    *** The test program failed to compile or link. See the file config.log for the
    *** exact error that occurred. This usually means GTK+ is incorrectly installed.
    However, pacman says:

$ pacman -Ss mingw-w64-x86_64-gtk3
mingw64/mingw-w64-x86_64-gtk3 3.24.49-1 [installed]
GObject-based multi-platform GUI toolkit (v3) (mingw-w64)

In my book 3.24.49 is >= 3.24.24; or is the trailing “-1” in the version a problem

You have some files left from previous attempts. The files are blocked by Windows, likely because you killed applications rather than exiting them. You need to clean the mess up. Reboot Windows delete the source directory. Create it again.