1

I try to compile a very simple GtkAda application in command-line, on Windows. Here is the app code:

`WITH Gtk.Main ;       USE Gtk.Main ; 
WITH Gtk.Window ;     USE Gtk.Window ; 
PROCEDURE Test01 IS
   win : Gtk_window ;
BEGIN
   Init ; 
   Gtk_New(Win) ;
   Win.show_all ; 
   Main ; 
END Test01 ;`

Compiling with

gcc -c test01.adb -IC:\<<path_to_GtkAda\include\gtkada>>, I obtain test.ali and test01.o as expected.

But how to link the libs please?

gcc test.o -LC:\<<path_to_GtkAda>>\lib

gives:

`Test01.o:Test01.adb:(.text+0xe): undefined reference to `gtk__main__init'
Test01.o:Test01.adb:(.text+0x21): undefined reference to `gtk__window__gtk_new'
Test01.o:Test01.adb:(.text+0x3e): undefined reference to `__gnat_rcheck_CE_Access_Check'
Test01.o:Test01.adb:(.text+0x5e): undefined reference to `gtk__main__main'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: Test01.o: bad reloc address 0x20 in section `.eh_f
rame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status`

PATH already contains <<path_to_GtkAda>>/bin

Thank you.

yO_
  • 1,135
  • 2
  • 12
  • 18

1 Answers1

3

The solution usually is to use GNAT's project files as described in the documentation installed with the compiler, typically in the “doc” or "doc/gprbuild” subdirectory.

A simple example project file named “SO.gpr” might look like this:

with "gtkada";
project SO is

 for Source_Dirs use (".");

end SO;

Note the part that says with "gtkada";. It means that the toolchain then will inject all switches that are necessary to make an Ada/GTK program. Then, if you invoke the GNAT toolchain like this:

$ gnatmake -PSO test01.adb

the Ada make program will call, in sequence, gcc, gnatbind, and gnatlink. For each, the necessary arguments to the commands will be supplied automatically. (Depending on which edition of GNAT you are using, you may also use gprbuild.)

So, for example on a Debian/GNU system with libgtkada2.24.4-dev installed, I see this:

$ gnatmake -Pso test01.adb
gcc-4.9 -c -I- -gnatA /home/bauhaus/News/SO/test01.adb
gnatbind -shared -x /home/bauhaus/News/SO/test01.ali
gnatlink /home/bauhaus/News/SO/test01.ali -shared-libgcc -L/usr/lib/x86_64-linux-gnu/ -lgtkada -lgdk-x11-2.0 -lgmodule-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lfontconfig -lfreetype -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lX11 -lm -o /home/bauhaus/News/SO/test01
$
B98
  • 1,229
  • 12
  • 20