Recent

Author Topic: How to reduce EXE program size?  (Read 2006 times)

lainz

  • Hero Member
  • *****
  • Posts: 4044
  • Leandro Diaz
Re: How to reduce EXE program size?
« Reply #15 on: April 11, 2021, 04:21:42 pm »
Yes, FPC is quite small. I tested with Rust x64 and I get a binary of 132 kb in release mode.

This is the Rust program I've used.
Code: Text  [Select][+][-]
  1. fn main() {
  2.    
  3. }

Edit: I know it has nothing to do with file size, but I also tried Kotlin native, and at least with their IDE it never ends compiling  :D FPC is quite fast as well compiling.
« Last Edit: April 11, 2021, 04:32:21 pm by lainz »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9284
  • FPC developer.
Re: How to reduce EXE program size?
« Reply #16 on: April 11, 2021, 04:32:50 pm »
Is the Code::Blocks binary standalone ?

Yes it's a C program, an exe that just requires the native dll from Windows.

So msvcrt is linked in statically?

Fred vS

  • Hero Member
  • *****
  • Posts: 2210
    • StrumPract is the musicians best friend
Re: How to reduce EXE program size?
« Reply #17 on: April 11, 2021, 04:36:58 pm »
Yes, FPC is quite small.

Hum, not so small as GCC ad clang

Code: C  [Select][+][-]
  1. int main() {
  2.    
  3. }

with gcc-8 64 bit linux: 16.1 Kb.
with clang-7 64 bit linux: 14.0 Kb.

But yes, fpc does it small.

« Last Edit: April 11, 2021, 05:02:32 pm by Fred vS »
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

lainz

  • Hero Member
  • *****
  • Posts: 4044
  • Leandro Diaz
Re: How to reduce EXE program size?
« Reply #18 on: April 11, 2021, 04:49:33 pm »
So msvcrt is linked in statically?

Good question =)

But I'm not sure, what I know is that it can use different compilers.

Quote
Multiple compiler support:

GCC (MingW / GNU GCC)
MSVC++
clang
Digital Mars
Borland C++ 5.5
Open Watcom
…and more

It must depend on the compiler you choose?

How I can detect that if I install it?

y.ivanov

  • Full Member
  • ***
  • Posts: 110
Re: How to reduce EXE program size?
« Reply #19 on: April 11, 2021, 04:59:51 pm »
Code: C  [Select][+][-]
  1. int main()
  2. {
  3. }
Is actually quite nothing. Include a printf() statement to add some beef.

MSVC by default compiles against msvcrt.dll. You can link statically with an option.

Can't compare binaries between Win/Linux, the executable format is quite different.

Regards,

lainz

  • Hero Member
  • *****
  • Posts: 4044
  • Leandro Diaz
Re: How to reduce EXE program size?
« Reply #20 on: April 11, 2021, 05:01:05 pm »
Hey anyways, if I want to install Cyberpunk 2077 it uses 70 GB of disk space, and I can put it together with my less than 100kb dummy program  :D

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9284
  • FPC developer.
Re: How to reduce EXE program size?
« Reply #21 on: April 11, 2021, 05:02:40 pm »
So msvcrt is linked in statically?

Good question =)

But I'm not sure, what I know is that it can use different compilers.

But you used only one to create that smaller file.

Quote
How I can detect that if I install it?

If you mean how you can detect how it works, check the DLLs that loads. Even if msvcrt comes with Windows, comparing a compiler with a runtime that is packaged with the OS to one that is not is only confusing the picture.

FlierMate

  • Guest
Re: How to reduce EXE program size?
« Reply #22 on: April 11, 2021, 05:04:05 pm »
FlierMate, the compiler option I meant is -Xg

It made the EXE larger: 33,811 bytes. If I just type "FPC firstapp.pas" without the "-Xg" then it generates 33,280 bytes.
49KB EXE is a result compiling it in the IDE itself.

That's the quick fix. Commenting some initializations in various standard units and maintain that as a custom RTL. Think about things like localisation, timezone support, thread support etc. Slightly harder is returning the string support back to the pre unicode level.

Ah, I see. I'll do it if I have special needs. Thanks.
BTW, years ago, I remember the EXE was way smaller. Looks like the RTL has grown over the years.

Not trivial and not for a one week-end project, I would say.

True.

And I agree with you completely, there is always pros and cons. Usually we could not please everyone.

Hum, not so small as GCC

Code: C  [Select][+][-]
  1. int main() {
  2.    
  3. }

with gcc 64 bit linux: 12.5 Kb.

If one coded using Assembler, a "Hello World" EXE as small as 1,024 bytes is possible. But of course it would be a lot more diificult to code in that language.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 512
  • Professional amateur ;-P
Re: How to reduce EXE program size?
« Reply #23 on: April 11, 2021, 05:16:48 pm »
Hey FlierMate,

And I agree with you completely, there is always pros and cons. Usually we could not please everyone.

Quite right, you can never appease Roman and Trojan(Old Portuguese saying)

If one coded using Assembler, a "Hello World" EXE as small as 1,024 bytes is possible. But of course it would be a lot more diificult to code in that language.

I particularly avoided going here, because it's the low hanging fruit.

Nonetheless, from the old day of MS-DOS, there was a guaranteed way that real programmers did it the smallest:
Code: DOS  [Select][+][-]
  1. COPY CON PROGRAM.EXE

Mic drop... :D :P

And if they needed to distribute:
Code: DOS  [Select][+][-]
  1. COPY CON PROGRAM.ZIP

Cheers,
Gus
Lazarus 2.1.0(trunk) FPC 3.3.1(trunk) Ubuntu 20.10 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.0(stable) Ubuntu 20.10 64b Dark Theme
http://github.com/gcarreno

Fred vS

  • Hero Member
  • *****
  • Posts: 2210
    • StrumPract is the musicians best friend
Re: How to reduce EXE program size?
« Reply #24 on: April 11, 2021, 05:17:14 pm »
If one coded using Assembler, a "Hello World" EXE as small as 1,024 bytes is possible. But of course it would be a lot more diificult to code in that language.

Of course with Assembler, but imho, Pascal is more comparable with C.

And about size, re-imho fpc size of executable are fairly reasonable.
It was not the case for libraries, -XX parameters was not enabled for them, but since fpc 3.0.0, it is fixed ( @marcov  ;) )

I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

lainz

  • Hero Member
  • *****
  • Posts: 4044
  • Leandro Diaz
Re: How to reduce EXE program size?
« Reply #25 on: April 11, 2021, 05:18:28 pm »
But you used only one to create that smaller file.
....
If you mean how you can detect how it works, check the DLLs that loads. Even if msvcrt comes with Windows, comparing a compiler with a runtime that is packaged with the OS to one that is not is only confusing the picture.

Hi, that's ok. Is like the C# executables are even smaller, but they require .NET installed. I understand.

But I did not compared the sizes, it was GetMem:

Quick test: FPC 3.2.0 vs. CodeBlocks 20.3, 32 bit "Hello world" application, both in release mode:
1. FPC 3.2.0:  33,280 bytes
2. CodeBlocks: 18,944 bytes

Where is the big difference?  Yes, the binary generated by FPC is slightly larger, but I don't think this is problem, not for me at least. :)

I did just a Rust comparison on my post, not a C one:

Yes, FPC is quite small. I tested with Rust x64 and I get a binary of 132 kb in release mode.

This is the Rust program I've used.
Code: Text  [Select][+][-]
  1. fn main() {
  2.    
  3. }

Edit: I know it has nothing to do with file size, but I also tried Kotlin native, and at least with their IDE it never ends compiling  :D FPC is quite fast as well compiling.

y.ivanov

  • Full Member
  • ***
  • Posts: 110
Re: How to reduce EXE program size?
« Reply #26 on: April 11, 2021, 05:38:08 pm »
@lainz
Rust? Kotlin? Really?

IMHO, nothing can beat C in code compactness. It is made for that! Furthermore, in Linux GCC apps are linked dynamically against all libraries. It is not like MSVC just against a single msvcrt.dll. And, AFAIK, the FPC has the monolithic approach, i.e. to link everything statically.

You're comparing oranges with apples.

So, what was the intention of the guy who started the topic? I'm lost.

Regards,

lainz

  • Hero Member
  • *****
  • Posts: 4044
  • Leandro Diaz
Re: How to reduce EXE program size?
« Reply #27 on: April 11, 2021, 05:45:07 pm »
@lainz
Rust? Kotlin? Really?

IMHO, nothing can beat C in code compactness. It is made for that! Furthermore, in Linux GCC apps are linked dynamically against all libraries. It is not like MSVC just against a single msvcrt.dll. And, AFAIK, the FPC has the monolithic approach, i.e. to link everything statically.

You're comparing oranges with apples.

So, what was the intention of the guy who started the topic? I'm lost.

Regards,

Hey why not?

Comparing a programming language resulting .exe with it's final size. That's it.

FlierMate

  • Guest
Re: How to reduce EXE program size?
« Reply #28 on: April 11, 2021, 05:46:15 pm »
So, what was the intention of the guy who started the topic? I'm lost.

It all started when I tried to use "Optimization- Generate smaller code"(see screenshot) in compiler option as well as Smart-linking. But both do not seem to work. So this is what puzzled me.

Fred vS

  • Hero Member
  • *****
  • Posts: 2210
    • StrumPract is the musicians best friend
Re: How to reduce EXE program size?
« Reply #29 on: April 11, 2021, 05:49:42 pm »
@lainz
Rust? Kotlin? Really?

IMHO, nothing can beat C in code compactness. It is made for that! Furthermore, in Linux GCC apps are linked dynamically against all libraries. It is not like MSVC just against a single msvcrt.dll. And, AFAIK, the FPC has the monolithic approach, i.e. to link everything statically.

You're comparing oranges with apples.

So, what was the intention of the guy who started the topic? I'm lost.

Regards,

Hello y.ivanov.

I think that it is the same for everybody starting with fpc (included me, of course).

The size of the executable that is bigger than with their comparable compilers concurrents.

This question come back each year, like a wave, but the good news is that in practice, each new fpc release produces smaller exe.

And yes, fpc produces bigger exe than his concurrents, but fpc does not have any competitor for cross-compilations, for his huge numbers of targets, his human-pascal-language, his hot forum with mad people and much more.

Amen.

Fre;D


I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

 

TinyPortal © 2005-2018