smallest fpc program size lazarus / 62-General ---------------------------------------------------------------------- fcu · 2017-07-17 09:55 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 · 2017-07-17 10:55 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 · 2017-07-17 11:17 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 · 2017-07-17 13:11 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/offMentioning mingw and exe I don't think he was refering to target embedded ---------------------------------------------------------------------- fcu · 2017-07-17 13:46 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit fpintres; interface implementation end.  main.pas Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc -Os -Us systemfpc -Os sysinitpasfpc -Os -XsX -CX main.pas ---------------------------------------------------------------------- marcov · 2017-07-17 13:51 Quote from: fcu on July 17, 2017, 03:46:52 pmforgot to mention iam using fpc for win32 (You might also try the nativent target) ---------------------------------------------------------------------- fcu · 2017-07-17 14:10 Quote from: marcov on July 17, 2017, 03:51:32 pmQuote from: fcu on July 17, 2017, 03:46:52 pmforgot to mention iam using fpc for win32 (You might also try the nativent target) how ? ---------------------------------------------------------------------- marcov · 2017-07-17 14:28 Afaik there are no releases, so you have to build it yourself. But maybe it is more system oriented than win32. E.g. with  make clean cycle OS_TARGET=nativent in compiler/ ---------------------------------------------------------------------- fcu · 2017-07-17 15:01 thanks , i'll take a look ---------------------------------------------------------------------- Thaddy · 2017-07-17 15:11 Quote from: avra on July 17, 2017, 03:11:37 pmQuote 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/offMentioning mingw and exe I don't think he was refering to target embedded  I know... Did you grasp what I wrote? But loose the weight of all I/O etc. and it just needs startup code. System.pas is way overblown. You can strip-out 95% (e.g. KOL's sysdcu for Delphi) of it when needed. You'll end up with about the same size as a C program that doesn't use any libraries: bytes, well within a KiloByte. But you need skills to do so. NativeNT will not help very much: it is basically Windows with ~5% of the code linked in. And most definitely will lead to more questions about why things do not work (yes, they stripped any convenience for a couple of bytes and then want it back!)..... Especially Pascal programmers do not compare like for like... (and learn to compare their code to C code). FPC makes it actually possible to come very close to - or better - than C if you know WHY your minimal executable is larger than a minimal C program.... Not many people here, not even experienced ones on this forum, do.. Such questions always arize... They are always by people who do not understand what is happening. They are always by people who want the convenience of everything that is in system.pas but do not want the ballast... You can hear them squeel... ---------------------------------------------------------------------- marcov · 2017-07-17 15:17 Quote from: Thaddy on July 17, 2017, 05:11:21 pm WHY your minimal executable is larger than a minimal C program.... Not many people here, not even experienced ones on this forum, do.. So, you are happy with the Size Matters faq now ?  I'll give the url since it is appropriate: http://wiki.freepascal.org/Size_Matters ---------------------------------------------------------------------- Thaddy · 2017-07-17 15:20 Ahum. You are one of those that do know... I can just help by writing the same faq in a more offensive way...