So I've been playing with Ada for some time, it's an awesome language, but I can't figure out how to make executables smaller (I'm using GNAT 5.3 on windows). Currently, file size of hello world is about 800 kb. When i strip debugging info it becomes ~222 kb. Any ideas how to make it smaller?
-
The User's Guide has a section on reducing executable size. It used to be about *gnatelim*, but the ways may have changed recently. Have you tried these suggestions, e.g. likely option `-Os`? – B98 Jan 08 '16 at 20:44
-
@B98 Yeah, I've read it. Gnatelim doesn't seem to work on windows, at least mingw-w64 doesn't have gnatelim. I've tried '-ffunction-sections -fdata-sections -Wl,–gc-sections', but it doesn't help at all. '-Os' doesn't help ether. – Sergey Polyansky Jan 08 '16 at 20:58
5 Answers
Ada.Text_IO
is featureful. If you don’t need all its capabilities, try GNAT.IO
; on Mac OS X (FSF GCC 5.1), the unstripped executable went down from 360816 bytes to 166356, stripped from 192200 to 83540.
Another thing: for some reason, GNAT doesn’t use shared libraries (DLLs) unless you tell it to. Forcing dynamic linking (gnatmake -O2 hello -bargs -shared
) reduced the Ada.Text_IO
version to 17520 bytes (14304 stripped), and the GNAT.IO
version to 13976 bytes (11888 stripped).

- 25,108
- 2
- 35
- 62
I don't think it is very meaningful to get a minimum size hello world program in Ada.
Ada's run time does have a bigger payload than C's.
Here is a discussion on it: https://groups.google.com/forum/#!topic/comp.lang.ada/1zvvW0Mw5Bw

- 428
- 3
- 4
If you're just interested in making the "Hello World" executable smaller, you could import write()
and use that instead of Ada.Text_IO
.

- 6,733
- 17
- 22
FYI: Standard Hello World on GNU/Hurd with its setup of gnatmake is around 16kB. Stripped around 8.5kB. No fancy tricks but probably gnat.adc with restrictions.

- 156
- 2
- 5
In the days when size was an issue, I occasionally used UPX. I believe it's still around.

- 1
- 1