How to distribute a GtkAda application under Windows?

240 Views Asked by At

I'm having troubles distributing a GtkAda application on Windows. I made an executable (with Windows native compiler) and tried using it on another Windows computer. However, I get errors about dlls missing.

I tried distributing with my .exe three folders.

  • bin including the dlls installed by GtkAda,
  • etc including fonts, gtk-3.0 and pango,
  • lib including gtk-3.0 with dlls too.

This is what I read from the GtkAda documentation

I think I maybe forgot to specify something in the project file

Here my GPS project file

with "C:\GNAT\GTK\lib\gnat\gtkada";

project Logfilter is
    for Source_Dirs use ("src");
    for Object_Dir  use "obj";
    for Exec_Dir    use "exec";
    for Main use ("log_filter_main.adb");

    package Builder is
      for Executable ("main.adb") use "Logs_Filter";
    end Builder;

    package Compiler is
      for Switches ("ada") use ("-Wl,--subsystem,windows");
    end Compiler;

end Logfilter;

I'm using a glade (gtk 3.14) file and GtkAda 2019.

Thank you.

1

There are 1 best solutions below

1
On BEST ANSWER

Where did you put the main executable (log_filter_main.exe)? What libraries are missing?

When I create a directory structure using the batch program below (change the variables GTKADA_INSTALL_DIR and TARGET_DIR to match your situation), and then copy my executable (a simple GtkAda program) into %TARGET_DIR%\bin, then this executable runs just fine. It's important that the application resides in the bin folder such that the correct GTK runtime libraries will be found during startup.

create_standalone.bat

SET GTKADA_INSTALL_DIR=C:\GNAT\2019\GtkAda
SET TARGET_DIR=C:\Test

xcopy /s /i %GTKADA_INSTALL_DIR%\bin\*.dll       %TARGET_DIR%\bin\
xcopy /s /i %GTKADA_INSTALL_DIR%\etc\*.*         %TARGET_DIR%\etc\
xcopy /s /i %GTKADA_INSTALL_DIR%\lib\gtk-3.0\*.* %TARGET_DIR%\lib\gtk-3.0\

REM  Copy your GtkAda application (.exe and other dependencies if applicable) 
REM  to %TARGET_DIR%\bin\

Regarding the project file: first, it's not completely clear why the Builder package is needed, but I might lack some project specific knowledge/requirements here. Second, if you want to get rid of the console window popping up when starting the GUI application, then you might want to use

package Linker is
  for Switches ("ada") use ("-mwindows");
end Linker;

instead of

package Compiler is
  for Switches ("ada") use ("-Wl,--subsystem,windows");
end Compiler;

Note:

Small additional note beyond the scope of the question (you may already have thought of it): please do not forget to quit the GTK main application when you close the main window. Define (for example):

procedure Destroy_Event_Callback
   (Widget : access Gtk.Widget.Gtk_Widget_Record'Class)
is
begin
   Gtk.Main.Main_Quit;
end Destroy_Event_Callback;

and then register it as a callback when the main window is initialized:

Main_Window.On_Destroy (Destroy_Event_Callback'Access);

If the Gtk.Main.Main_Quit call is omitted, then the program (process) will keep running after you close the main window (at least when you use the -mwindows linker option).