Original date:2017-06-26 09:16:45 Edited by: ghaberek Subject: Re: Optimizing size of executable

Note: I wrote this answer yesterday but apparently forgot to hit Post.

rneu said...

For a simplest program:

puts(1, "Hello World!\n")

using compiler command:



euc -con

I get an executable of size 194 kb. The size is no problem here but may be an issue with larger programs. Are there any options that I can use to optimize the size of executable?

[Just a note: With Chicken Scheme ( ), for a similar simple program, I get an executable sized only 16 kb.]

Euphoria includes a lot of runtime code into translated executables to implement the required memory management and dynamic object routines. This is going to add some bloat to the executable, but it's helpful and necessary bloat.

There are three ways to reduce the size of an executable:

  • Use the GCC "optimize for size" option -Os (the default is -O2)
  • Use the GNU strip utility to remove symbols (included with MinGW)
  • Use the UPX packer to apply compression (download from UPX)

Here is the program I compiled for this test. I included std/io.e to add some complexity to the program.

-- demo.ex 
include std/io.e 
procedure main() 
    puts( STDOUT, "hello, world\n" ) 
end procedure 

Here is the command I ran to create a makefile, which I can then edit.

euc -build-dir build -makefile demo.ex 

You can compile the executable on Windows like this. On Linux, just specify make.

mingw32-make -j4 -C build -f demo.mak 

The line you need to change for -Os is at the top of the makefile:

CFLAGS =  -DEWINDOWS -fomit-frame-pointer -c -w -fsigned-char -Os -m32 -IC:/Euphoria -ffast-math 

Here are the sizes I got through combining all the options:

Option Size Savings
-O2 362 KB 0%
-Os 350 KB 3%
-O2 + strip 279 KB 23%
-Os + strip 267 KB 26%
-O2 + upx 193 KB 47%
-Os + upx 187 KB 48%
-O2 + strip + upx 110 KB 70%
-Os + strip + upx 104 KB 71%

Your mileage may vary with larger executables.


Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu