Forum > General
smallest fpc program size
fcu:
Hi
how to generate the samllest exe size with fpc without embedded rtl ?
with mingw only passing -nosdtlib and rename main function to _main gives me 1.5kb exe
thanks
marcov:
Use smartlinking and strip debugging. In theory also optimization for size, but that is peanuts. This should give you something 30kbish, and that is currently the best you can do on windows without modifying the RTL.
The smallest files DOS com files I guess. But probably the 16-bit dos RTL also counts as "embedded".
Thaddy:
Note there is always a trade off:
- embedded: you can count in bytes, not Kb, to turn e.g. a led on/off
- full blown OS's (more useful, more generic) FPC already encapsulates a lot that e.g. c does not.
- what are your requirements?
- What is your platform? Because that makes a huge difference.
What Marco wrote is just about right for both Linux and Windows: 30K ish. But for embedded devices you can go as low as just a couple of 100's of bytes.
If you are skilled enough, you could just use embedded mode with just the startup code and always end up within ~ 1000 bytes.
Stripping the system to what's required....
avra:
--- Quote from: Thaddy on July 17, 2017, 01:17:19 pm ---- embedded: you can count in bytes, not Kb, to turn e.g. a led on/off
--- End quote ---
Mentioning mingw and exe I don't think he was refering to target embedded ;)
fcu:
forgot to mention iam using fpc for win32 ;)
smartlinking and strip are on by default if you just type : fpc programname.pas , which gives 31kb for empty app .
ok i think i found how to get the smallest size .
fpc needs : system.pas , sysinitpas.pas , fpintres.pas
after emptying those files and let only the Entry procedure i get 3.5kb for a MessageBox App ;)
you can try your self
system.pas
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit system; interface type HResult = longint;implementation procedure FPC_INITIALIZEUNITS; [public, alias: 'FPC_INITIALIZEUNITS'];beginend; procedure FPC_DO_EXIT; [public, alias: 'FPC_DO_EXIT'];beginend; end.
sysinitpas.pas
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit sysinitpas; interface implementation procedure PASCALMAIN; external name 'PASCALMAIN'; procedure ExitProcess(ExitCode: longint); stdcall; external 'kernel32.dll' name 'ExitProcess'; procedure Entry; [public, alias: '_mainCRTStartup'];begin PASCALMAIN; ExitProcess(0);end; end.
fpintres.pas
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit fpintres; interface implementation end.
main.pas
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program test;type pchar = ^char; function MessageBox(hwnd:longint; msg,title:pchar; op:longint):longint; stdcall external 'user32.dll' name 'MessageBoxA'; begin MessageBox(0,'FPC 3.5kb App',';)',0);end.
compiling with :
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---fpc -Os -Us systemfpc -Os sysinitpasfpc -Os -XsX -CX main.pas
Navigation
[0] Message Index
[#] Next page