Recent

Author Topic: Is it possible to create smaller executable  (Read 1871 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 266
Is it possible to create smaller executable
« on: January 21, 2023, 10:46:05 am »
Hello freepascal experts,

I am cross compiling from WIN64 to ARM

Lazarus version 2.3.0 FPC version 3.3.1

And it works fine.

except that my executebale is already about 30 megabytes

does anybody know about settings in the IDE to create a smaller executable?

Otherwise it takes to long in my copy script to copy it on my Raspberry.

Greets, pascalbythree


KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Is it possible to create smaller executable
« Reply #1 on: January 21, 2023, 10:51:19 am »
As a start, turning debug information off would drastic reduce compiled size.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

ccrause

  • Hero Member
  • *****
  • Posts: 988
Re: Is it possible to create smaller executable
« Reply #2 on: January 21, 2023, 12:53:05 pm »
As a start, turning debug information off would drastic reduce compiled size.
^ this is step 1

2. Read the documentation on Optimization switches, and Tips to get smaller code. Based on these references add the following compiler options:
  • Enable optimization, pick from: -O3, -O4 or -Os
  • Enable smart linking: -CX -XX
  • Strip symbols from executable: -Xs

Finally, if this is not enough: Whole program optimization (WPO).

Thaddy

  • Hero Member
  • *****
  • Posts: 16390
  • Censorship about opinions does not belong here.
Re: Is it possible to create smaller executable
« Reply #3 on: January 21, 2023, 02:22:40 pm »
And after all that you can use an exe packer like UPX.
There is nothing wrong with being blunt. At a minimum it is also honest.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11990
  • FPC developer.
Re: Is it possible to create smaller executable
« Reply #4 on: January 21, 2023, 02:36:08 pm »
And after all that you can use an exe packer like UPX.

Wouldn't recommend that in general, but specifically not for such new targets as Windows/arm

pascalbythree

  • Sr. Member
  • ****
  • Posts: 266
Re: Is it possible to create smaller executable
« Reply #5 on: January 22, 2023, 05:37:00 pm »
Thank you, it works fine. Can not get it lower than 851KB

But that is fine for now.

Now i want to disable my cache, continuing at www.stackoverflow.com

https://stackoverflow.com/questions/75202059/cross-compiling-freepascal-lazarus-from-winx64-to-raspbian-linux-raspberry-3-dis

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Is it possible to create smaller executable
« Reply #6 on: January 22, 2023, 08:05:25 pm »
For windows you can also code pure native, like using native controls (by implementing proper code on your own)
You can search for some examples that uses native WinAPI, than final executables are from 15kb (with Delphi, I did not tried with FPC yet) up to an unknown size depending on what you insert in code.
If that is possible for Linux or other platforms = idk.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Scoops

  • Full Member
  • ***
  • Posts: 103
Re: Is it possible to create smaller executable
« Reply #7 on: January 22, 2023, 08:39:20 pm »
hello

https://forum.lazarus.freepascal.org/index.php?topic=30027.0


I used these components but i really did need just very simple
message and buttons, on windows so as for cross compiling
etc i cant say if its ok for your needs. Dont know if its
updated either. take a look.

Ah just realised it was 5 or 6 years ago
« Last Edit: January 22, 2023, 09:21:31 pm by Scoops »

 

TinyPortal © 2005-2018