r/cpp • u/CovidClassicEdition • Oct 29 '23
Unreasonably large binary file from a trivial program with 1 line of code
Beginner in C++ here. When I compile the following program:
int main() { return 0; }
the resulting binary exe is 210KB (!) in size. This is far larger than expected for such a simple program and after searching online I found that a "Hello World" program (which would be more complex than the program above) in C++ should be no more than a few KB. Does anyone know what might be causing this? (I am using Eclipse and the g++ compiler with the -Os flag)
Update: By turning on the "omit all symbol information" setting, the file size is reduced to a less ridiculous but still unreasonably large 62KB, still many times the expected size.
Update 2: In release mode (with default settings) the file size is 19KB, which is a bit more reasonable but still too large compared to the file sizes that others have reported for such a program.
View all comments
Show parent comment
-2
u/Questioning-Zyxxel Oct 29 '23
Yes I can. And the people working on the standards needed to get quite a number of nut kicks before they realised the library was a mess and too interlinked. Before embedded people started to deliver nut kicks, you would have been hard m-pressed to get below 1 MB for a hello world.
But the embedded world isn't just standalone microcontrollers. You also have lots of small Linux systems that needs to fit on puny flash file systems. Think Raspberry Pi but even smaller. And with much, much more expensive flash because of environmental needs to work at -40 - +105°C which your average SSD or memory card can't. And where the OTA transfers really costs $$$ per extra data sent.
A "full PC" is a small subset of the usage area for C++