How to build single program from the TESTGTK collection
- Test environment
Ubuntu 22.04.1 LTS
GNAT GTKAda 2021 Adacore
PC: HP Envy 17t-S100
How to take one of the sample programs from the testgtk collection and build it individually
Sample application: progress bar starting with testgtk
Purpose: Simplify the evaluation by starting only one program.
Static build (default)
Create 2 new directories.
- ada/test6A-static
- ada/test6A-static/src
Copy 4 files from the testgtk directory into src directory.
- common.adb
- common.ads
- create_progress.adb
- create_progress.ads
NOTE: Check the adb file you want to build.
If it has “with Common; use Common”, you need to build with common.adb and common.ads as above sample.
Otherwise, you can build without common.adb and common.ads
Startup gnatstudio
~/ada/test6A-static$ gnatstudio
- Choose “+Create New Project”
- Choose “GtkAda”—”Simple window”—next
- Change Setting—Project Name from “default” to “progress”—Apply
Now, GNAT Studio is opened
Just for our reference, new progress.gpr file was created by gnatstudio as:
~/ada/test6A-static$ cat progress.gpr
with "gtkada";
project Progress is
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Main use ("main.adb");
end Progress;
Choose gnatstudio “Edit” tab—”Project Properties”
Check if Source files are correct
“Sources”—”Files”—Choose “Source files” radio button
The source files (x4) and main.adb(x1) files are displayed
Check if Main file is set correct
Press “Save”
The progress.gpr file was updated and we will use this gpr:
~/ada/test6A-static$ cat progress.gpr
with "gtkada";
project Progress is
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Main use ("main.adb");
for Source_Files use ("common.adb", "common.ads", "create_progress.adb", "create_progress.ads", "main.adb");
end Progress;
Change main.adb
The file src/main.adb was created by gnatstudio automatically, and it displays only “Hello world”.
with Gdk.Event; use Gdk.Event;
with Gtk.Box; use Gtk.Box;
with Gtk.Label; use Gtk.Label;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Main;
with Gtk.Window; use Gtk.Window;
procedure Main is
Win : Gtk_Window;
Label : Gtk_Label;
Box : Gtk_Vbox;
function Delete_Event_Cb
(Self : access Gtk_Widget_Record'Class;
Event : Gdk.Event.Gdk_Event)
return Boolean;
---------------------
-- Delete_Event_Cb --
---------------------
function Delete_Event_Cb
(Self : access Gtk_Widget_Record'Class;
Event : Gdk.Event.Gdk_Event)
return Boolean
is
pragma Unreferenced (Self, Event);
begin
Gtk.Main.Main_Quit;
return True;
end Delete_Event_Cb;
begin
-- Initialize GtkAda.
Gtk.Main.Init;
-- Create a window with a size of 400x400
Gtk_New (Win);
Win.Set_Default_Size (400, 400);
-- Create a box to organize vertically the contents of the window
Gtk_New_Vbox (Box);
Win.Add (Box);
-- Add a label
Gtk_New (Label, "Hello world.");
Box.Add (Label);
-- Stop the Gtk process when closing the window
Win.On_Delete_Event (Delete_Event_Cb'Unrestricted_Access);
-- Show the window and present it
Win.Show_All;
Win.Present;
-- Start the Gtk+ main loop
Gtk.Main.Main;
end Main;
Modify main.adb to display progress window
with Gdk.Event; use Gdk.Event;
with Gtk.Box; use Gtk.Box;
with Gtk.Label; use Gtk.Label;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Main;
with Gtk.Window; use Gtk.Window;
-- ****** Add DEFINITION ***********
with Gtk.Frame; use Gtk.Frame;
with Create_Progress; use Create_Progress;
--**********************************
procedure Main is
Win : Gtk_Window;
--****** COMMENT OUT 1 LINES ******
-- Label : Gtk_Label;
--*********************************
Box : Gtk_Vbox;
-- ****** ADD DEFINITION **********
frame1 : Gtk_frame;
--*********************************
function Delete_Event_Cb
(Self : access Gtk_Widget_Record'Class;
Event : Gdk.Event.Gdk_Event)
return Boolean;
---------------------
-- Delete_Event_Cb --
---------------------
function Delete_Event_Cb
(Self : access Gtk_Widget_Record'Class;
Event : Gdk.Event.Gdk_Event)
return Boolean
is
pragma Unreferenced (Self, Event);
begin
Gtk.Main.Main_Quit;
return True;
end Delete_Event_Cb;
begin
-- Initialize GtkAda.
Gtk.Main.Init;
-- Create a window with a size of 400x400
Gtk_New (Win);
Win.Set_Default_Size (400, 400);
-- Create a box to organize vertically the contents of the window
Gtk_New_Vbox (Box);
Win.Add (Box);
--****** COMMENT OUT 2 LINES *******
-- Add a label
-- Gtk_New (Label, "Hello world.");
-- Box.Add (Label);
---*********************************
--****** ADD 3 lines ***************
Gtk.Frame.Gtk_New (frame1);
Add (Box, frame1);
Create_Progress.Run(frame1); --**** CALL Package.Procedure
--**********************************
-- Stop the Gtk process when closing the window
Win.On_Delete_Event (Delete_Event_Cb'Unrestricted_Access);
-- Show the window and present it
Win.Show_All;
Win.Present;
-- Start the Gtk+ main loop
Gtk.Main.Main;
end Main;
Build all
~/ada/test6A-static/obj$ ls -al main
-rwxrwxr-x 1 mm mm 4963008 Dec 26 09:31 main — 4.96MB file was created
RUN
CHECK build and run without gnatstudio
Used the same new progress.gpr and main.adb, and 4 other source files.
Create new folders and copy the
Build with gprbuild
~/ada/test6A-gprbuild$ gprbuild
using project file progress.gpr
Setup
[mkdir] object directory for project Progress
Compile
[Ada] main.adb
[Ada] create_progress.adb
[Ada] common.adb
Bind
[gprbind] main.bexch
[Ada] main.ali
Link
[link] main.adb
~/ada/test6A-gprbuild$ cd obj
~/ada/test6A-static-gprbuild/obj$ ls -al main
-rwxrwxr-x 1 mm mm 4963008 Dec 4 16:16 main
~/ada/test6A-gprbuild/obj$ ./main
NOTE
After switching “static” and “relocatable”, the mode may stick at the next new project.
In such a situation, change the environments as follows:
If relocatable sticks (on the gnatstudio message)
gprbuild -d -P/home/mm/ada/test6A-static/progress.gpr -XGTKADA_BUILD=relocatable -XLIBRARY_TYPE=relocatable
These 2 commands fix the issue:
$ export LIBRARY_TYPE=static
$ export GTKADA_BUILD=static
Switched to static (on the gnatstudio message)
gprbuild -d -P/home/mm/ada/test6A-static/progress.gpr -XGTKADA_BUILD=static -XLIBRARY_TYPE=static