Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Statically Linking SFML and Executable Size Reduction  (Read 2261 times)

0 Members and 1 Guest are viewing this topic.

Moonkis

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Statically Linking SFML and Executable Size Reduction
« on: March 06, 2013, 02:25:31 pm »
I know most people don't really bother with this, but I have a relatively small project ( A graphical console ) which I'm trying to reduce the size of.

So far I'v been searching and trying out link-flags and compiler-flags like a mad man, but at it's smallest I'v been able to reduce it to 1,4 mb ( 1'430 KB ) which I still think is large.

I came across this: http://stackoverflow.com/questions/12449387/bloated-exe-sizes-and-unwanted-dependencies-with-qt-mingw

But even when re-compiling SFML with this ( and -s ) the size is still very large, I only noticed a very ( VERY small ) difference in size.

Is there any other way to NOT include code that isn't going to be used or am I doing something wrong, and/or reduce the size of an SFML executable ( other than UPX )?

I'm compiling with MinGW ( g++ ) and Code::Blocks.

I'm really fascinated on how to reduce executable size.

Kind regards Moonkis.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Statically Linking SFML and Executable Size Reduction
« Reply #1 on: March 06, 2013, 02:38:51 pm »
The question always his how much benefit you get from it and how much time you want to invest into it.
I'm sure you're familiar with demos, well the main challenge there is to reduce the file size. They often achieve this insanely good, but it's also a lot of work and you really need to know what you're doing, otherwise you'll screw things over quite badly.

Seeing as more and more people are connected with good bandwidth and the harddrive space doesn't matter as much, it seems to me not really worth spending time on reducing file sizes without having a really good reason to do so.

But of course there are many many many tricks you can use to do so. The first step is always to play around with the compiler flags. If you then want to reduce the built in libraries file size, you can go and instead of linking against a static library just add the sources you need to your project. From there you can trim down the class to only the essential stuff and start inlineing and copying code around.
As you might guess at this point things already are quite messy and you lose a lot of the flexibility.

Alternative and/or in addition to messing around with the code directly, you can use a so called packer. Packers take your binary and remove unnessecary stuff and even compress other stuff, thus resulting in quite a small binary.
UPX is well-known for this.
This has the advantage that you don't actually have to mess around with the code (if you don't want to), but can also lead to certain anti-virus applications flagging your application, because viruses etc. use similar approaches and AVs can't detect the difference.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/